Added lost error page

This commit is contained in:
T T 2018-11-06 18:50:24 +01:00
parent 9360aeea76
commit 6d98ec50f5
2 changed files with 11 additions and 0 deletions

View File

@ -125,11 +125,16 @@ func (s *Server) FormPage(w http.ResponseWriter, r *http.Request) {
formTemplate.Execute(w, config)
}
func (s *Server) ErrorPage(w http.ResponseWriter, r *http.Request) {
errorTemplate.Execute(w, config)
}
func main() {
var io FsIo
server := Server{Io: &io}
http.HandleFunc(RequestStatusUrlPrefix, server.RequestPage)
http.HandleFunc(FormPostUrl, server.FormPostHandler)
http.HandleFunc(FormUrl, server.FormPage)
http.HandleFunc(ErrorUrl, server.ErrorPage)
log.Fatal(http.ListenAndServe("localhost:5678", nil))
}

View File

@ -18,6 +18,12 @@ var statusTemplate = template.Must(footer.New("status").Parse(`
Status: {{ .Status }}
{{ template "footer" .Global }}`))
var errorTemplate = template.Must(footer.New("error").Parse(`
{{ template "header" . }}
<p>Error, all form fields must be field.</p>
<a href="/">take ma back</a>
{{ template "footer" . }}`))
var formTemplate = template.Must(header.New("form").Parse(`{{ template "header" . }}
<h1>~🐱 Sign up form</h1>
<form action="/post" method="post">