From a834bfab9f02f399a22a40529bc4ca4fa69514e0 Mon Sep 17 00:00:00 2001 From: Tom Andrade Date: Wed, 1 May 2019 00:54:20 +0200 Subject: [PATCH] optimize port check --- main.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index 7d63687..1751b43 100644 --- a/main.go +++ b/main.go @@ -102,14 +102,6 @@ func shortner(w http.ResponseWriter, r *http.Request) { break } } - var hostSuf string - if port != "80" && proto == "http" { - hostSuf = ":" + port + "/" - } else if port != "443" && proto == "https" { - hostSuf = ":" + port + "/" - } else if port == "443" || port == "80" { - hostSuf = "/" - } set(u.String(), suffix) shortend := proto + "://" + domain + hostSuf + path + suffix returnTmpl.Execute(w, shortend) @@ -219,8 +211,12 @@ func main() { if port > 65535 || port < 1 { } - if path != "" && !strings.HasSuffix(path, "/") { - path = path + "/" + if port != 80 && proto == "http" { + hostSuf = ":" + strconv.Itoa(port) + "/" + } else if port != 443 && proto == "https" { + hostSuf = ":" + strconv.Itoa(port) + "/" + } else if port == 443 || port == 80 { + hostSuf = "/" } ip := net.ParseIP(addr) if ip != nil {