diff --git a/main.go b/main.go index ae63e60..d40c497 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,9 @@ package main import ( + "bytes" "embed" + "encoding/csv" "fmt" "html/template" "log" @@ -33,15 +35,23 @@ func handleForm(w http.ResponseWriter, r *http.Request) { } now := time.Now().UTC().Format(time.RFC3339) - entry := strings.Join([]string{now, details.Label, details.Url}, ",") - log.Print("inserting: ", entry) + entry := strings.Join([]string{now, "unknown", details.Label, details.Url}, ",") insertEntry(entry) tmpl.Execute(w, struct{ Success bool }{true}) } +func handleRequested(w http.ResponseWriter, r *http.Request) { + tmpl := template.Must(template.ParseFS(indexHTML, "templates/requested.html")) + file, _ := os.ReadFile("requests.txt") + requests, _ := csv.NewReader(bytes.NewReader(file)).ReadAll() + + tmpl.Execute(w, struct{ Requests [][]string }{requests}) +} + func setupRoutes() { http.HandleFunc("/", handleForm) + http.HandleFunc("/requested", handleRequested) http.ListenAndServe(":8080", nil) } diff --git a/templates/index.html b/templates/index.html index cd190bc..5e81a27 100644 --- a/templates/index.html +++ b/templates/index.html @@ -10,14 +10,22 @@ padding: 2rem; margin: auto; } + + nav>a { + margin: 1ch; + }
+