I solved gophercises and on the second exercise I wrote this code:
func mapHandler(
provider func(string) (string, error),
w http.ResponseWriter,
r *http.Request) {
longUrl, err := provider(r.URL.Path)
if err != nil {
w.WriteHeader(http.StatusNotFound)
fmt.Fprintln(w, err.Error())
return
}
w.Header().Add("Location", longUrl)
w.WriteHeader(http.StatusTemporaryRedirect)
}
But on the solution of exercise I see this method: http.Redirect(...) So,
I looked into implementation of that method, and discovered that it do
redirection via html, but Mozilla
<https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections> write it
about redirection:
HTTP redirects are the best way to create redirections, but sometimes you
don't have control over the server.
And redirection in that case, is the case where I have control over the
server, so what's the reason of redirection via html?
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/golang-nuts/e52f2809-8f53-42ad-af43-6239444827d8n%40googlegroups.com.