forked from LunaNode/lobster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
splash.go
47 lines (38 loc) · 1.1 KB
/
splash.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package lobster
import "net/http"
type SplashTemplateParams struct {
Title string
Message string
Token string
}
func getSplashHandler(template string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
message := ""
if r.URL.Query()["message"] != nil {
message = r.URL.Query()["message"][0]
}
params := SplashTemplateParams{
Title: template,
Message: message,
}
RenderTemplate(w, "splash", template, params)
}
}
func getSplashFormHandler(template string) func(w http.ResponseWriter, r *http.Request, session *Session) {
return func(w http.ResponseWriter, r *http.Request, session *Session) {
message := ""
if r.URL.Query()["message"] != nil {
message = r.URL.Query()["message"][0]
}
params := SplashTemplateParams{
Title: template,
Message: message,
Token: CSRFGenerate(session),
}
RenderTemplate(w, "splash", template, params)
}
}
func splashNotFoundHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404)
RenderTemplate(w, "splash", "notfound", SplashTemplateParams{Title: "404 Not Found"})
}