-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
164 lines (156 loc) · 3.46 KB
/
handler.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package main
import (
"github.com/anhgelus/golatt"
"github.com/gorilla/mux"
"net/http"
)
func handleHome(w http.ResponseWriter, _ *http.Request) {
var seasonsData []*SeasonData
i := 0
for _, v := range seasons {
seasonsData = append(seasonsData, &SeasonData{
Left: i%2 == 0,
Title: v.Name,
Description: v.Information.Description,
Image: v.Logo,
ImageAlt: "Logo de " + v.Name,
Href: "/season/" + v.ID,
})
i++
}
g.Render(w, "index", &golatt.TemplateData{
Title: "Architects Land",
SEO: &golatt.SeoData{
URL: "/",
Image: "terre-des-civilisations/background.webp",
Description: "Famille de SMP Minecraft privé",
},
Data: struct {
HasFooter bool
HasNav bool
Hero *HeroData
Seasons []*SeasonData
}{
HasFooter: true,
HasNav: true,
Hero: &HeroData{
Title: "Architects Land",
Description: "Famille de SMP Minecraft privé",
Image: "terre-des-civilisations/background.webp",
Dark: false,
Min: false,
},
Seasons: seasonsData,
},
})
}
func handleSeason(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
id, ok := vars["id"]
if !ok {
handleNotFound(w, r)
return
}
season, ok := GetSeason(id)
if !ok {
handleNotFound(w, r)
return
}
g.Render(w, "season/index", &golatt.TemplateData{
Title: season.Name,
SEO: &golatt.SeoData{
URL: "/season/" + season.ID,
Image: season.Image,
Description: season.Description,
},
Data: struct {
HasFooter bool
HasNav bool
Hero *HeroData
Season *FullSeasonData
}{
HasFooter: true,
HasNav: true,
Hero: &HeroData{
Title: season.Name,
Description: season.Description,
Image: season.Image,
Dark: false,
Min: true,
},
Season: season.toFullSeasonData(),
},
})
}
func handlePlayer(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
id, ok := vars["id"]
if !ok {
handleNotFound(w, r)
return
}
season, ok := GetSeason(id)
if !ok {
handleNotFound(w, r)
return
}
pseudo, ok := vars["player"]
if !ok {
handleNotFound(w, r)
return
}
var player *SeasonPlayer
for _, p := range season.Players {
if p.Pseudo == pseudo {
player = p
}
}
if player == nil {
handleNotFound(w, r)
return
}
g.Render(w, "season/player", &golatt.TemplateData{
Title: player.Name + " - " + season.Name,
SEO: &golatt.SeoData{
URL: "/season/" + season.Name + "/" + player.Pseudo,
Image: "skins/" + player.Pseudo + ".png",
Description: player.Description,
},
Data: struct {
HasFooter bool
HasNav bool
Season *Season
Player *SeasonPlayer
}{
HasFooter: false,
HasNav: false,
Season: season,
Player: player,
},
})
}
func handleNotFound(w http.ResponseWriter, _ *http.Request) {
g.Render(w, "lost", &golatt.TemplateData{
Title: "404",
SEO: &golatt.SeoData{
URL: "",
Image: "nether.webp",
Description: "Il semblerait que vous vous êtes perdu·es dans le nether. (Erreur 404)",
},
Data: struct {
HasFooter bool
HasNav bool
Hero *HeroData
}{
HasFooter: false,
HasNav: false,
Hero: &HeroData{
Title: "Perdu ?",
Description: "Il semblerait que vous vous êtes perdu·es dans le nether. Vous allez être redirigés dans l'overworld.",
Image: "nether.webp",
Dark: false,
Min: false,
},
},
})
}