This is a created article in which the information may have evolved or changed.
Call HTTP. The Redirect () function does not jump immediately, but continues to execute all the code in the function in sequence before jumping. However, the code behind the redirect will not be sent to the front of the browser.
The code is as follows:
Func Chat (w http. Responsewriter, R *http. Request) {fmt. Println ("Chat") R.parseform () withwho: = R.form.get ("withwho") type towho struct {Name string}if ret: = Checkcookie (R); ret = = "" | | "" = = Withwho{url: = "/login"http. Redirect (w,r, URL, http. Statusfound)}towho: = towho{name:withwho}t, err: = template. Parsefiles ("templates/html/chat.html") checkerror (err) Err = T.execute (w, towho) checkerror (err)
}
Although the red (Redirect) function is executed, the green code is executed, but the parsed chat.html file is not written to the client as it was previously. Why is that? Do not understand AH. So it's better to add return after redirect.