summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-07 15:36:18 -0400
committerdemo <demo@antix1>2026-05-07 15:36:18 -0400
commit9c1d8f97aae6454d86c6efdfde03e17cf7ea61ed (patch)
treeee3d078a7a30ed68c63d0cc091a411ec59a48afc
parent5f3ebd07dc7b416e4ef32a1f45fe6d077e6abe68 (diff)
feat: implement Config to house template needed by Handler
-rw-r--r--internal/types/types.go12
-rw-r--r--main.go6
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))
}