blob: b431eaf139dc4ca2022c208cbae13ea4d261c139 (
plain)
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
|
package types
import (
"fmt"
"html/template"
"net/http"
)
type option struct {
Text string
Arc string
}
type arc struct {
Title string
Story []string
Options []option
}
type story map[string]arc
type Config struct {
*template.Template
Story story
}
func (cfg Config) ServeHTTP(w http.ResponseWriter, r *http.Request) {
arcName := r.PathValue("arc")
arc, ok := cfg.Story[arcName]
if !ok {
msg := fmt.Sprintf("Arc with name %s doesn't exist", arcName)
http.Error(w, msg, http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "text/html")
if err := cfg.ExecuteTemplate(w, "index", arc); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
|