Directly join short link string
This commit is contained in:
parent
9d557f5272
commit
c6552f825f
9
main.go
9
main.go
|
@ -9,7 +9,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -82,13 +81,7 @@ func ShortenHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
writeShortenedUrl := func(w http.ResponseWriter, slug string) {
|
writeShortenedUrl := func(w http.ResponseWriter, slug string) {
|
||||||
shortenedUrl, err := url.Parse(viper.GetString("shortUrl"))
|
_, _ = w.Write([]byte(viper.GetString("shortUrl") + "/" + slug))
|
||||||
if err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
shortenedUrl.Path = slug
|
|
||||||
_, _ = w.Write([]byte(shortenedUrl.String()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
requestUrl := r.URL.Query().Get("url")
|
requestUrl := r.URL.Query().Get("url")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user