-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_resources.go
91 lines (77 loc) · 2.09 KB
/
template_resources.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"context"
"html/template"
"log"
"net/http"
"github.com/gorilla/sessions"
tmpl "github.com/pocketsign/link-subscriber-api-example/template"
)
const (
// 各種リソースのID
nameResourceID = "50f423aa-8ea8-4385-81a1-a7d8da1c4939"
birthDateResourceID = "612c6a3c-212a-402e-8c89-792a4b3e7889"
addressResourceID = "5419c333-2863-4d57-9272-5f6c6c8989ec"
genderResourceID = "5ac941bf-88f3-47e3-b2e7-3bb0522aa14b"
)
type templateUserResources struct {
Name string
BirthDate string
Address string
Gender string
Custom string
}
func getTemplateUserResources(ctx context.Context, sess *sessions.Session) *templateUserResources {
res := &templateUserResources{
Name: "データの取得に失敗しました",
BirthDate: "データの取得に失敗しました",
Address: "データの取得に失敗しました",
Gender: "データの取得に失敗しました",
Custom: "",
}
// 各種ユーザーリソースをAPIを通して取得
name, err := getUserResource(ctx, sess, nameResourceID)
if err != nil {
log.Println(err)
} else {
res.Name = name.Value
}
birthDate, err := getUserResource(ctx, sess, birthDateResourceID)
if err != nil {
log.Println(err)
} else {
res.BirthDate = birthDate.Value
}
address, err := getUserResource(ctx, sess, addressResourceID)
if err != nil {
log.Println(err)
} else {
res.Address = address.Value
}
gender, err := getUserResource(ctx, sess, genderResourceID)
if err != nil {
log.Println(err)
} else {
res.Gender = gender.Value
}
custom, err := getUserResource(ctx, sess, customResourceID)
if err != nil {
log.Println(err)
} else {
res.Custom = custom.Value
}
return res
}
func execTemplate(ctx context.Context, sess *sessions.Session, w http.ResponseWriter) {
tmpl, err := template.ParseFS(tmpl.F, "index.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
input := getTemplateUserResources(ctx, sess)
err = tmpl.Execute(w, input)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}