I am writing a small app using web.go with a function that serves a form. If the form is not valid, user will be redirected to the same page:
func mypage(ctx *web.Context) {
if ctx.Request.Method == "GET" {
// show the form
} else if ctx.Request.Method == "POST" {
// redirection if the form is not valid:
ctx.Request.Method = "GET"
http.Redirect(ctx.ResponseWriter,
ctx.Request, "/mypage", http.StatusNotAcceptable)
return
}
}
This works, with one caveat that when the form is not valid, it first shows a page with the text "Not Acceptable"
that is liked to /mypage
. How can I make it to go directly to /mypage
in case the form is not valid? I suspect that it is related to http.StatusNotAcceptable
but I don't know what I should replace it with.