From d047c36dd09b6169bf27c244196e99bb5df54c3a Mon Sep 17 00:00:00 2001 From: Mitchell Date: Sat, 20 Mar 2021 01:37:03 -0400 Subject: Update documentation. Remove all traces of chdir from the steam library. Remove most linter complaints. --- cmd/web/handlers.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'cmd/web/handlers.go') diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index b9b863a..661c411 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -14,6 +14,8 @@ import ( "riedstra.dev/mitch/steam-export/steam" ) +// HandleIndex takes care of rendering our embedded template +// and locks the steam library for each 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 @@ -36,7 +38,7 @@ func (a *App) HandleIndex(w http.ResponseWriter, r *http.Request) { &a.Library.Library, a.Status, isLocal(r.RemoteAddr), - getHostIP(), + GetHostIP(), getPort(), Version, }) @@ -46,6 +48,8 @@ func (a *App) HandleIndex(w http.ResponseWriter, r *http.Request) { Logger.Printf("Client %s Index page", r.RemoteAddr) } +// HandleInstall takes the HTTP requests for installing a game from a URL +// or local file path func (a *App) HandleInstall(w http.ResponseWriter, r *http.Request) { err := r.ParseForm() if err != nil { @@ -78,6 +82,7 @@ func (a *App) HandleInstall(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/", 302) } +// HandleDownload takes care of exporting our games out to an HTTP request func (a *App) HandleDownload(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) game := vars["game"] @@ -129,6 +134,9 @@ func (a *App) HandleDownload(w http.ResponseWriter, r *http.Request) { Logger.Printf("Client %s finished downloading: %s", r.RemoteAddr, game) } +// HandleDelete removes the game in question, though it doesn't +// spawn any background processes it usually completes fast enough. +// TODO: Fix if the request taking too long becomes an issue func (a *App) HandleDelete(w http.ResponseWriter, r *http.Request) { err := r.ParseForm() if err != nil { @@ -166,6 +174,8 @@ func (a *App) HandleDelete(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/", 302) } +// HandleStats dumps out some internal statistics of installation which +// is then parsed by some JS for a progress bar and such func (a *App) HandleStats(w http.ResponseWriter, r *http.Request) { a.Status.RLock() defer a.Status.RUnlock() @@ -181,6 +191,7 @@ func (a *App) HandleStats(w http.ResponseWriter, r *http.Request) { return } +// HandleSetLib sets a new library path func (a *App) HandleSetLib(w http.ResponseWriter, r *http.Request) { err := r.ParseForm() if err != nil { @@ -194,6 +205,7 @@ func (a *App) HandleSetLib(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/", 302) } +// HandleQuit just calls os.Exit after finishing the request func HandleQuit(w http.ResponseWriter, r *http.Request) { Logger.Println("Quit was called, exiting") w.Header().Add("Content-type", "text/plain") -- cgit v1.2.3