Added proper redirection, improved loading error display
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
"qurl/static"
|
||||
"qurl/storage"
|
||||
"qurl/qurl"
|
||||
)
|
||||
|
||||
type RootHandler struct {
|
||||
@ -39,7 +40,19 @@ func (ctx *RootHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
ctx.ServeAPI(w, r)
|
||||
|
||||
default:
|
||||
fmt.Printf("Path: %s\n", fname)
|
||||
id, err := qurl.FromString(fname[1:len(fname)])
|
||||
if err != nil {
|
||||
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
|
||||
}
|
||||
|
||||
q, err := ctx.Storage.GetQURLByID(id)
|
||||
if err != nil {
|
||||
http.Error(w, fmt.Sprintf("Database error: %s", err.Error()),
|
||||
http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, q.URL, http.StatusPermanentRedirect)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user