package types
import (
"html/template"
"log"
"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 {
log.Printf("Arc with name %s doesn't exist", arcName)
http.Error(w, "Page not found", http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "text/html")
if err := cfg.ExecuteTemplate(w, "index", arc); err != nil {
log.Print(err)
http.Error(w, "Something went wrong!", http.StatusInternalServerError)
return
}
}