diff options
Diffstat (limited to 'internal/types')
| -rw-r--r-- | internal/types/types.go | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/internal/types/types.go b/internal/types/types.go index 3772f1f..b431eaf 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -1,8 +1,8 @@ package types import ( + "fmt" "html/template" - "io" "net/http" ) @@ -20,14 +20,21 @@ type arc struct { type story map[string]arc type Config struct { - Story story - Template *template.Template + *template.Template + Story story } func (cfg Config) ServeHTTP(w http.ResponseWriter, r *http.Request) { - arc := r.PathValue("arc") - title := cfg.Story[arc].Title + 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/plain") - io.WriteString(w, title) + w.Header().Set("Content-Type", "text/html") + if err := cfg.ExecuteTemplate(w, "index", arc); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } } |
