-
Notifications
You must be signed in to change notification settings - Fork 0
/
static.go
58 lines (49 loc) · 1.25 KB
/
static.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
48
49
50
51
52
53
54
55
56
57
58
package handler
import (
"net/http"
"github.com/gorilla/sessions"
"github.com/utilyre/ssa/internal/router"
"github.com/utilyre/ssa/internal/templates"
"github.com/utilyre/xmate"
)
type staticHandler struct {
store sessions.Store
tmpls templates.Templates
}
func HandleStatic(
r router.Router,
store sessions.Store,
t templates.Templates,
) {
h := staticHandler{
store: store,
tmpls: t,
}
r.HandleFunc("/", h.home).Methods(http.MethodGet)
r.HandleFunc("/signup", h.signup).Methods(http.MethodGet)
r.HandleFunc("/login", h.login).Methods(http.MethodGet)
}
func (h staticHandler) home(w http.ResponseWriter, r *http.Request) error {
session, err := h.store.Get(r, "ssa-login")
if err != nil {
return err
}
return xmate.WriteHTML(w, h.tmpls.Pages, http.StatusOK, xmate.Map{
"Name": "home",
"Payload": xmate.Map{
"Email": session.Values["email"],
},
})
}
func (h staticHandler) signup(w http.ResponseWriter, r *http.Request) error {
return xmate.WriteHTML(w, h.tmpls.Pages, http.StatusOK, xmate.Map{
"Name": "signup",
"Payload": nil,
})
}
func (h staticHandler) login(w http.ResponseWriter, r *http.Request) error {
return xmate.WriteHTML(w, h.tmpls.Pages, http.StatusOK, xmate.Map{
"Name": "login",
"Payload": nil,
})
}