Refactoring variables names/usage

This commit is contained in:
Tom Andrade 2019-04-29 21:30:15 +02:00
parent ecbc575db7
commit c61ddfbc79
Signed by: wolvie
GPG Key ID: 31AAB07872E82669

15
main.go
View File

@ -63,21 +63,22 @@ func get(key string) (string, bool) {
}
// set executes the redis SET command
func set(url, suffix string) {
pool.Set(suffix, url, 0)
func set(key, suffix string) {
pool.Set(suffix, key, 0)
}
func redirect(w http.ResponseWriter, r *http.Request) {
vals := mux.Vars(r)
val := vals["key"]
key := vals["key"]
if path != "" {
val = strings.Replace(val, path, "", 1)
key = strings.Replace(key, path, "", 1)
}
rgx, _ := regexp.Compile("[a-zA-Z0-9]+")
key := rgx.FindString(val)
url, status := get(key)
key = rgx.FindString(key)
key, status := get(key)
u, _ := url.Parse(key)
if status {
http.Redirect(w, r, url, http.StatusFound)
http.Redirect(w, r, u.String(), http.StatusFound)
} else {
w.WriteHeader(http.StatusNotFound)
notFoundTmpl.Execute(w, notFoundTmpl)