diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2021-03-04 18:50:47 -0500 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2021-03-04 18:50:47 -0500 |
| commit | 3b6f5647b0689abf04be73c3cf00297051753435 (patch) | |
| tree | 3de6871abf37849c1e9f86dfc90ee2b3ed74c66e /cmd/web/index.go | |
| parent | eaf02771d767e4745572d9b00e71e138ee030e60 (diff) | |
| download | steam-export-3b6f5647b0689abf04be73c3cf00297051753435.tar.gz steam-export-3b6f5647b0689abf04be73c3cf00297051753435.tar.xz | |
Refactor. Pull most of the functions into methods off of an App struct.
Kill most global variables.
Diffstat (limited to 'cmd/web/index.go')
| -rw-r--r-- | cmd/web/index.go | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/cmd/web/index.go b/cmd/web/index.go index b90faf8..7291af0 100644 --- a/cmd/web/index.go +++ b/cmd/web/index.go @@ -1,31 +1,22 @@ package main import ( - "html/template" "net/http" - _ "embed" "riedstra.dev/mitch/steam-export/steam" ) -var ( - //go:embed templates/index.html - indexTemplate string - - Templ = template.Must(template.New("index").Parse(indexTemplate)) -) - -func index(w http.ResponseWriter, r *http.Request) { +func (a *App) HandleIndex(w http.ResponseWriter, r *http.Request) { // During rendering of the template I believe it's // mutating during the sort of keys, so Lib no longer // is an RWMutex and we're just locking this as if // we're writing to it - Lib.Lock() - defer Lib.Unlock() - status.Lock() - defer status.Unlock() + a.Library.Lock() + defer a.Library.Unlock() + a.Status.Lock() + defer a.Status.Unlock() - err := Templ.ExecuteTemplate(w, "index", + err := a.Templates.ExecuteTemplate(w, "index", struct { Lib *steam.Library Info *statusInfo @@ -34,8 +25,8 @@ func index(w http.ResponseWriter, r *http.Request) { Port string Version string }{ - &Lib.Library, - status, + &a.Library.Library, + a.Status, isLocal(r.RemoteAddr), getHostIP(), getPort(), |
