forked from security/hakurei
cmd/pkgserver: do not assume default mux
This helps with testing. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -36,7 +36,7 @@ func serveInfo(index *PackageIndex) func(http.ResponseWriter, *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func serveStatus(index *PackageIndex, cache *pkg.Cache) func(w http.ResponseWriter, r *http.Request) {
|
||||
func serveStatus(index *PackageIndex) func(w http.ResponseWriter, r *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
download := path.Dir(r.URL.Path) == "/status"
|
||||
if index == nil {
|
||||
@@ -125,11 +125,11 @@ func serveGet(index *PackageIndex) func(http.ResponseWriter, *http.Request) {
|
||||
|
||||
const ApiVersion = "v1"
|
||||
|
||||
func apiRoutes(index *PackageIndex, cache *pkg.Cache) {
|
||||
http.HandleFunc(fmt.Sprintf("GET /api/%s/info", ApiVersion), serveInfo(index))
|
||||
http.HandleFunc(fmt.Sprintf("GET /api/%s/get", ApiVersion), serveGet(index))
|
||||
http.HandleFunc(fmt.Sprintf("GET /api/%s/status/", ApiVersion), serveStatus(index, cache))
|
||||
http.HandleFunc("GET /status/", serveStatus(index, cache))
|
||||
func apiRoutes(mux *http.ServeMux, index *PackageIndex) {
|
||||
mux.HandleFunc(fmt.Sprintf("GET /api/%s/info", ApiVersion), serveInfo(index))
|
||||
mux.HandleFunc(fmt.Sprintf("GET /api/%s/get", ApiVersion), serveGet(index))
|
||||
mux.HandleFunc(fmt.Sprintf("GET /api/%s/status/", ApiVersion), serveStatus(index))
|
||||
mux.HandleFunc("GET /status/", serveStatus(index))
|
||||
}
|
||||
|
||||
func WritePayload(w http.ResponseWriter, payload any) {
|
||||
|
||||
Reference in New Issue
Block a user