cmd/pkgserver: constant string in pattern

This resolves patterns at compile time.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-03-11 02:23:43 +09:00
parent e130443cf4
commit a1b515074e
3 changed files with 9 additions and 7 deletions

View File

@@ -106,12 +106,14 @@ func (index *packageIndex) handleGet(w http.ResponseWriter, r *http.Request) {
}{len(values), values})
}
const ApiVersion = "v1"
// apiVersion is the name of the current API revision, as part of the pattern.
const apiVersion = "v1"
func apiRoutes(mux *http.ServeMux, index *packageIndex) {
mux.HandleFunc(fmt.Sprintf("GET /api/%s/info", ApiVersion), handleInfo)
mux.HandleFunc(fmt.Sprintf("GET /api/%s/get", ApiVersion), index.handleGet)
mux.HandleFunc(fmt.Sprintf("GET /api/%s/status/", ApiVersion), index.handleStatus)
// registerAPI registers API handler functions.
func (index *packageIndex) registerAPI(mux *http.ServeMux) {
mux.HandleFunc("GET /api/"+apiVersion+"/info", handleInfo)
mux.HandleFunc("GET /api/"+apiVersion+"/get", index.handleGet)
mux.HandleFunc("GET /api/"+apiVersion+"/status/", index.handleStatus)
mux.HandleFunc("GET /status/", index.handleStatus)
}