Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
fever-ch
GitHub Repository: fever-ch/go-google-sites-proxy
Path: blob/master/proxy/errorpage.go
508 views
1
package proxy
2
3
import (
4
"github.com/fever-ch/go-google-sites-proxy/common"
5
"html/template"
6
"net/http"
7
)
8
9
const errorPageTmpl = `<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
10
<html><head>
11
<Title>{{.Title}}</Title>
12
</head><body>
13
<h1>{{.Title}}</h1>
14
<p>{{.Message}}</p>
15
<hr>
16
<address>{{.ProgramInfo.Name}} - {{.ProgramInfo.Version}}</address>
17
</body></html>`
18
19
func errorPage(code int, title string, message string) func(responseWriter http.ResponseWriter, request *http.Request) {
20
type ErrorPage struct {
21
Title string
22
Message string
23
ProgramInfo common.ProgramInfoStruct
24
}
25
26
t := template.New("")
27
tt, _ := t.Parse(errorPageTmpl)
28
29
e := ErrorPage{title, message, common.ProgramInfo}
30
31
return func(responseWriter http.ResponseWriter, request *http.Request) {
32
responseWriter.WriteHeader(code)
33
tt.Execute(responseWriter, e)
34
}
35
}
36
37