diff options
| author | demo <demo@antix1> | 2026-05-07 15:36:18 -0400 |
|---|---|---|
| committer | demo <demo@antix1> | 2026-05-07 15:36:18 -0400 |
| commit | 9c1d8f97aae6454d86c6efdfde03e17cf7ea61ed (patch) | |
| tree | ee3d078a7a30ed68c63d0cc091a411ec59a48afc | |
| parent | 5f3ebd07dc7b416e4ef32a1f45fe6d077e6abe68 (diff) | |
feat: implement Config to house template needed by Handler
| -rw-r--r-- | internal/types/types.go | 12 | ||||
| -rw-r--r-- | 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) @@ -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)) } |
