From 9c1d8f97aae6454d86c6efdfde03e17cf7ea61ed Mon Sep 17 00:00:00 2001 From: demo Date: Thu, 7 May 2026 15:36:18 -0400 Subject: feat: implement Config to house template needed by Handler --- internal/types/types.go | 12 +++++++++--- main.go | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/internal/types/types.go b/internal/types/types.go index 0800994..3772f1f 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -1,6 +1,7 @@ package types import ( + "html/template" "io" "net/http" ) @@ -16,11 +17,16 @@ type arc struct { Options []option } -type Story map[string]arc +type story map[string]arc -func (s Story) ServeHTTP(w http.ResponseWriter, r *http.Request) { +type Config struct { + Story story + Template *template.Template +} + +func (cfg Config) ServeHTTP(w http.ResponseWriter, r *http.Request) { arc := r.PathValue("arc") - title := s[arc].Title + title := cfg.Story[arc].Title w.Header().Set("Content-Type", "text/plain") io.WriteString(w, title) diff --git a/main.go b/main.go index 10ae4c7..c185441 100644 --- a/main.go +++ b/main.go @@ -31,14 +31,14 @@ func main() { log.Fatal(err) } - var story types.Story - if err := json.Unmarshal(jsonBytes, &story); err != nil { + var cfg types.Config + if err := json.Unmarshal(jsonBytes, &cfg.Story); err != nil { log.Fatal(err) } // Set up the handlers and server. mux := http.NewServeMux() - mux.Handle("/{arc}", &story) + mux.Handle("/{arc}", &cfg) log.Fatal(runServer(mux, *port)) } -- cgit v1.2.3