-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.go
48 lines (41 loc) · 1.03 KB
/
handlers.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
package main
import (
"encoding/json"
"log"
"net/http"
)
func (h *handler) handleIndex(w http.ResponseWriter, r *http.Request) {
sess, err := h.store.Get(r, "oidc-session")
if err != nil {
log.Println(err)
}
execTemplate(r.Context(), sess, w)
}
func (h *handler) handlePut(w http.ResponseWriter, r *http.Request) {
sess, err := h.store.Get(r, "oidc-session")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
v := struct {
Value string `json:"value"`
}{}
if err := json.NewDecoder(r.Body).Decode(&v); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// valueに渡す値を一度jsonに変換
b, err := json.Marshal(v.Value)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// 変換したjsonをvalueに渡す
rv := UserResource{
Value: string(b),
}
if err := putUserResource(r.Context(), sess, customResourceID, rv); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}