From c80dc1a2c569fa6de80b637be1ac623ab48cbc35 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sun, 28 Dec 2025 22:39:06 -0800 Subject: [PATCH] Use real environment variables for template rendering --- main.go | 34 +++++++++++++--------------------- static/index.html | 42 +++++++++++++++++++----------------------- 2 files changed, 32 insertions(+), 44 deletions(-) diff --git a/main.go b/main.go index 0e09618..44836b0 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - "bufio" "context" "encoding/json" "html/template" @@ -14,26 +13,9 @@ import ( "google.golang.org/api/idtoken" ) -var ( - env = map[string]string{} - templates *template.Template -) +var templates *template.Template func init() { - f, err := os.Open("secrets.env") - if err != nil { - log.Fatal("[ERROR] failed to open secrets.env: ", err) - } - defer f.Close() - - scanner := bufio.NewScanner(f) - for scanner.Scan() { - line := scanner.Text() - if parts := strings.SplitN(line, "=", 2); len(parts) == 2 { - env[parts[0]] = parts[1] - } - } - templates = template.Must(template.ParseGlob("static/*.html")) } @@ -60,13 +42,23 @@ func handleStatic(w http.ResponseWriter, r *http.Request) { return } w.Header().Set("Content-Type", "text/html") - t.Execute(w, env) + t.Execute(w, envMap()) return } http.ServeFile(w, r, filepath.Join("static", name)) } +func envMap() map[string]string { + m := map[string]string{} + for _, e := range os.Environ() { + if parts := strings.SplitN(e, "=", 2); len(parts) == 2 { + m[parts[0]] = parts[1] + } + } + return m +} + func handleGoogleCallback(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { http.Error(w, "method not allowed", http.StatusMethodNotAllowed) @@ -79,7 +71,7 @@ func handleGoogleCallback(w http.ResponseWriter, r *http.Request) { return } - payload, err := idtoken.Validate(context.Background(), credential, env["GOOGLE_CLIENT_ID"]) + payload, err := idtoken.Validate(context.Background(), credential, os.Getenv("GOOGLE_CLIENT_ID")) if err != nil { log.Println("[ERROR] failed to validate token:", err) http.Error(w, "invalid token", http.StatusUnauthorized) diff --git a/static/index.html b/static/index.html index 35919c6..0e23016 100644 --- a/static/index.html +++ b/static/index.html @@ -4,42 +4,38 @@ - Tickets App + HCA Tickets - -

Hello World

-

Welcome to the Tickets App!

-
-
- -
+
+
+
+