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) }) }