From c6552f825fe794be07d5c87764c3173b86fdeccc Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Sun, 29 Mar 2020 19:05:01 +0200 Subject: [PATCH] Directly join short link string --- main.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/main.go b/main.go index b3efa15..099f739 100644 --- a/main.go +++ b/main.go @@ -9,7 +9,6 @@ import ( "log" "math/rand" "net/http" - "net/url" "time" ) @@ -82,13 +81,7 @@ func ShortenHandler(w http.ResponseWriter, r *http.Request) { } writeShortenedUrl := func(w http.ResponseWriter, slug string) { - shortenedUrl, err := url.Parse(viper.GetString("shortUrl")) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - shortenedUrl.Path = slug - _, _ = w.Write([]byte(shortenedUrl.String())) + _, _ = w.Write([]byte(viper.GetString("shortUrl") + "/" + slug)) } requestUrl := r.URL.Query().Get("url")