Refactoring variables names/usage
This commit is contained in:
parent
ecbc575db7
commit
c61ddfbc79
15
main.go
15
main.go
@ -63,21 +63,22 @@ func get(key string) (string, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set executes the redis SET command
|
// set executes the redis SET command
|
||||||
func set(url, suffix string) {
|
func set(key, suffix string) {
|
||||||
pool.Set(suffix, url, 0)
|
pool.Set(suffix, key, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func redirect(w http.ResponseWriter, r *http.Request) {
|
func redirect(w http.ResponseWriter, r *http.Request) {
|
||||||
vals := mux.Vars(r)
|
vals := mux.Vars(r)
|
||||||
val := vals["key"]
|
key := vals["key"]
|
||||||
if path != "" {
|
if path != "" {
|
||||||
val = strings.Replace(val, path, "", 1)
|
key = strings.Replace(key, path, "", 1)
|
||||||
}
|
}
|
||||||
rgx, _ := regexp.Compile("[a-zA-Z0-9]+")
|
rgx, _ := regexp.Compile("[a-zA-Z0-9]+")
|
||||||
key := rgx.FindString(val)
|
key = rgx.FindString(key)
|
||||||
url, status := get(key)
|
key, status := get(key)
|
||||||
|
u, _ := url.Parse(key)
|
||||||
if status {
|
if status {
|
||||||
http.Redirect(w, r, url, http.StatusFound)
|
http.Redirect(w, r, u.String(), http.StatusFound)
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
notFoundTmpl.Execute(w, notFoundTmpl)
|
notFoundTmpl.Execute(w, notFoundTmpl)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user