func TestBasicHandler(w http.ResponseWriter, r *http.Request) { templates_dir, dir_err := env.GetQindTemplatesDir() if dir_err != nil { http.Error(w, dir_err.Error(), http.StatusInternalServerError) return } t, t_err := template.ParseFiles(templates_dir + string(filepath.Separator) + "test" + string(filepath.Separator) + "basic.html") if t_err != nil { http.Error(w, t_err.Error(), http.StatusInternalServerError) return } remote_addr, remote_addr_err := qind_net.ClientIP(r) if remote_addr_err != nil { http.Error(w, remote_addr_err.Error(), http.StatusInternalServerError) return } t.Execute(w, struct{ TestVar string }{remote_addr}) }
// MakeFormToken takes a request struct and a form target path and creates a HMAC'd form token. func MakeFormToken(r *http.Request,target_form_path string) (string,error) { hmac,hmac_err := env.GetQindHMACSalt() if hmac_err != nil { return "",hmac_err } remote_addr,remote_addr_err := qind_net.ClientIP(r) if remote_addr_err != nil { return "",remote_addr_err } token_text,token_text_err := FormTokenText(remote_addr,target_form_path) if token_text_err != nil { return "",token_text_err } token,token_err := HMACToken(token_text,hmac) if token_err != nil { return "",token_err } return token,nil }