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) } }