I have written a small piece of code in go
func loginHandler(w http.ResponseWriter, r *http.Request) {
log.Println("loginHandler")
log.Println("request url is", r.RequestURI)
log.Println("request method", r.Method)
requestbody, _ := ioutil.ReadAll(r.Body)
log.Println("request body is", string(requestbody))
if r.Method == "POST" {
us, err := globalSessions.SessionStart(w, r)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
us.Set("LoggedInUserID", "000000")
w.Header().Set("Location", "/auth")
w.WriteHeader(http.StatusFound)
return
}
outputHTML(w, r, "static/login.html")
}
func outputHTML(w http.ResponseWriter, req *http.Request, filename string) {
log.Println("outputHTML")
requestbody, _ := ioutil.ReadAll(req.Body)
log.Println("request body is", string(requestbody))
log.Println("request body is", requestbody)
file, err := os.Open(filename)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
defer file.Close()
fi, _ := file.Stat()
http.ServeContent(w, req, file.Name(), fi.ModTime(), file)
}
in this code i am redirecting to login.html . now i want to send a variable let it be some string called testvariable and its value to login.html.
</div>