In my request handler I have a conditional statement where I need to fetch the http status code.
func PostHandler(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
idStr := params["id"]
// how would I get the 307 status code, to decide whether to redirect or not?
if w.StatusCode != 307 { // does not work, no such field - why not???
http.Redirect(w, r, idStr, 307)
} else {
RenderTemplate()
}
}
m.HandleFunc("/{id:.*}", PostHandler).Methods("POST") // this is matched first to intercept POST requests with status 307
m.HandleFunc("/{id:.*}", MyHandler).Methods("GET", "POST")
I've made an example to help illustrate this concrete scenario:
http://play.golang.org/p/YZgTsVO524
How would I achieve this?
Basically I'm using the 307 because I need to resend my POST values the http.Redirect(w,r, url, code) destination. Afaik this seems to be the best way to do this, but again, I can't do it without the status code.
Additional question: is using 307 a bad solution? If so, what's a better alternative?