diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2021-08-04 20:06:07 -0400 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2021-08-04 20:06:07 -0400 |
| commit | 742938b00222c7ad57ad11eb24850d9202c2503d (patch) | |
| tree | e0d1d033027d5dd553c213ed41bb8ae201d6a285 /cmd | |
| parent | a5a49ff08056a67cc57435f219aa157342a0d9a0 (diff) | |
| download | steam-export-742938b00222c7ad57ad11eb24850d9202c2503d.tar.gz steam-export-742938b00222c7ad57ad11eb24850d9202c2503d.tar.xz | |
Pretty large structural changes. Non-building development snapshot
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/web/apiv1.go | 3 | ||||
| -rw-r--r-- | cmd/web/app.go | 10 | ||||
| -rw-r--r-- | cmd/web/main.go | 17 | ||||
| -rw-r--r-- | cmd/web/routes.go | 40 |
4 files changed, 46 insertions, 24 deletions
diff --git a/cmd/web/apiv1.go b/cmd/web/apiv1.go new file mode 100644 index 0000000..221e923 --- /dev/null +++ b/cmd/web/apiv1.go @@ -0,0 +1,3 @@ +package main + +import () diff --git a/cmd/web/app.go b/cmd/web/app.go index bc8385a..9ab1c0e 100644 --- a/cmd/web/app.go +++ b/cmd/web/app.go @@ -8,12 +8,6 @@ import ( "riedstra.dev/mitch/steam-export/steam" ) -// steamLib is a steam libary with an embeded mutex to protect it -type steamLib struct { - steam.Library - sync.Mutex -} - // statusInfo represents the internal status of game installation type statusInfo struct { sync.RWMutex @@ -76,8 +70,8 @@ func (a *App) LibrarySet(path string) { Logger.Println("Done reloading lib") } -// LibraryReload calls LibrarySet but with the current directory, forcing a reload of -// information off of disk. +// LibraryReload calls LibrarySet but with the current directory, forcing a +// reload of information off of disk. func (a *App) LibraryReload() { cur := a.Library.Folder a.LibrarySet(cur) diff --git a/cmd/web/main.go b/cmd/web/main.go index 6db58d9..045f60a 100644 --- a/cmd/web/main.go +++ b/cmd/web/main.go @@ -10,8 +10,6 @@ import ( "os" "strconv" "strings" - - "github.com/gorilla/mux" ) var ( @@ -55,20 +53,7 @@ func main() { go a.installer() - r := mux.NewRouter() - - r.Handle("/quit", UnauthorizedIfNotLocal(http.HandlerFunc(HandleQuit))) - r.Handle("/setLib", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleSetLib))) - r.Handle("/delete", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleDelete))) - r.Handle("/install", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleInstall))) - r.HandleFunc("/steam-export-web.exe", ServeSelf) - r.HandleFunc("/download/{game}", a.HandleDownload) - r.Handle("/status", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleStats))) - r.PathPrefix("/static").Handler( - http.FileServer(http.FS(embeddedStatic))) - r.HandleFunc("/", a.HandleIndex) - - s := http.Server{Handler: r} + s := http.Server{Handler: a} for i := 0; i < 5; i++ { l, err := net.Listen("tcp", Listen) diff --git a/cmd/web/routes.go b/cmd/web/routes.go new file mode 100644 index 0000000..6d0e529 --- /dev/null +++ b/cmd/web/routes.go @@ -0,0 +1,40 @@ +package main + +import ( + "net/http" + + "github.com/gorilla/mux" +) + +func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) { + rtr := mux.NewRouter() + + rtr.PathPrefix("/api/v1").Handler(a.HandleAPIv1()) + + rtr.Handle("/quit", UnauthorizedIfNotLocal(http.HandlerFunc(HandleQuit))) + rtr.Handle("/setLib", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleSetLib))) + rtr.Handle("/delete", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleDelete))) + rtr.Handle("/install", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleInstall))) + rtr.Handle("/status", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleStats))) + + rtr.HandleFunc("/steam-export-web.exe", ServeSelf) + rtr.HandleFunc("/download/{game}", a.HandleDownload) + rtr.PathPrefix("/static").Handler( + http.FileServer(http.FS(embeddedStatic))) + rtr.HandleFunc("/", a.HandleIndex) + + rtr.ServeHTTP(w, r) +} + +func (a *App) HandleAPIv1() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + rtr := mux.NewRouter() + + rtr.Handle("/quit", UnauthorizedIfNotLocal(http.HandlerFunc(HandleQuit))) + rtr.Handle("/library", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleSetLib))) + rtr.Handle("/library/delete", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleSetLib))) + rtr.Handle("/library/delete", UnauthorizedIfNotLocal(http.HandlerFunc(a.HandleSetLib))) + + rtr.ServeHTTP(w, r) + }) +} |
