mirror of
https://github.com/aykhans/oh-my-url.git
synced 2025-12-15 18:09:20 +00:00
🎉 first commit
This commit is contained in:
26
app/http_handlers/url_forward.go
Normal file
26
app/http_handlers/url_forward.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package httpHandlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (hl *HandlerForward) UrlForward(w http.ResponseWriter, r *http.Request) {
|
||||
path := r.URL.Path
|
||||
segments := strings.Split(path, "/")
|
||||
if len(segments) > 2 {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
} else if segments[1] == "" {
|
||||
http.Redirect(w, r, hl.CreateDomain, http.StatusMovedPermanently)
|
||||
return
|
||||
}
|
||||
|
||||
key := segments[1]
|
||||
url, err := hl.DB.GetURL(key)
|
||||
if err != nil {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, url, http.StatusMovedPermanently)
|
||||
}
|
||||
Reference in New Issue
Block a user