Browse Source

Use http.Status Close #13

master
kreativmonkey 5 years ago
parent
commit
8cfebbeebf
  1. 4
      handlers.go
  2. 2
      shrty/urlinfo_test.go

4
handlers.go

@ -24,10 +24,10 @@ func index(w http.ResponseWriter, r *http.Request) {
// Redirect to the URL behind the requested token.
func redirect(w http.ResponseWriter, r *http.Request){
if redirect, ok := short.Redirect(r.URL.Path[1:]); ok{
http.Redirect(w, r, string(redirect), 301)
http.Redirect(w, r, string(redirect), http.StatusMovedPermanently)
fmt.Printf("Token: %s Redirect to: %s \n", string(r.URL.Path[1:]), redirect)
} else {
http.Redirect(w, r, "/", 301)
http.Redirect(w, r, "/", http.StatusMovedPermanently)
}
}

2
shrty/urlinfo_test.go

@ -28,7 +28,7 @@ func TestCheckURL(t *testing.T) {
func TestCheckURL2(t *testing.T) {
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(time.Second * 12)
time.Sleep(time.Second * 20)
}))
defer svr.Close()

Loading…
Cancel
Save