From bcf66d92d664dd707937ae866830a6bee0751745 Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Sat, 24 May 2025 12:52:32 -0500 Subject: cleanup all go code and add an index/home page that is composed from the readme file --- watch.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 watch.go (limited to 'watch.go') diff --git a/watch.go b/watch.go new file mode 100644 index 0000000..8352e62 --- /dev/null +++ b/watch.go @@ -0,0 +1,34 @@ +package main + +import ( + "html/template" + "net/http" +) + +var templateWatchFiles = []string{ "templates/base.html", "templates/watch.html" } +var templateWatch = template.Must(template.ParseFiles(templateWatchFiles...)) + +/* render template */ +type WatchTemplateData struct { + Id string +} + +func renderWatchTemplate(w http.ResponseWriter, id string) { + if debug { + reloadTemplate(&templateWatch, templateWatchFiles...) + } + err := templateWatch.Execute(w, WatchTemplateData{ + Id: id, + }) + if err != nil { + templateError(err, w) + } +} + +/* routes */ +func setupRoutesWatch() { + http.HandleFunc("/watch", func(w http.ResponseWriter, r *http.Request) { + id := r.URL.Query().Get("v") + renderWatchTemplate(w, id) + }) +} -- cgit v1.2.3