package gate import ( _ "embed" "html/template" "log" "net/http" ) //go:embed login.html var loginHTML string var loginTmpl = template.Must(template.New("login").Parse(loginHTML)) const ( msgWrong = "That password is not right." msgTooMany = "Too many attempts. Try again in a minute." ) type pageData struct { Host string Error string Next string Action string } // writePage renders the login page at status. Every page this package // writes is no-store and noindex: it is a curtain, not content. func writePage(w http.ResponseWriter, r *http.Request, host string, status int, msg, next string) { h := w.Header() h.Set("Cache-Control", "no-store") h.Set("X-Robots-Tag", "noindex, nofollow") h.Set("Content-Type", "text/html; charset=utf-8") w.WriteHeader(status) if r.Method == http.MethodHead { return } if err := loginTmpl.Execute(w, pageData{Host: host, Error: msg, Next: next, Action: LoginPath}); err != nil { log.Printf("gate: render login page for %s: %v", host, err) } }