From 91aa21d92d256e055130a0a3066f9f96ebc89884 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Wed, 11 Mar 2026 02:29:27 +0900 Subject: [PATCH] cmd/pkgserver: format get error messages This improves source code readability on smaller displays. Signed-off-by: Ophestra --- cmd/pkgserver/api.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/pkgserver/api.go b/cmd/pkgserver/api.go index 2a3d26a..6549e4a 100644 --- a/cmd/pkgserver/api.go +++ b/cmd/pkgserver/api.go @@ -81,21 +81,33 @@ func (index *packageIndex) handleStatus(w http.ResponseWriter, r *http.Request) } } +// handleGet writes a slice of metadata with specified order. func (index *packageIndex) handleGet(w http.ResponseWriter, r *http.Request) { q := r.URL.Query() limit, err := strconv.Atoi(q.Get("limit")) if err != nil || limit > 100 || limit < 1 { - http.Error(w, fmt.Sprintf("limit must be an integer between 1 and 100"), http.StatusBadRequest) + http.Error( + w, "limit must be an integer between 1 and 100", + http.StatusBadRequest, + ) return } i, err := strconv.Atoi(q.Get("index")) if err != nil || i >= len(index.sorts[0]) || i < 0 { - http.Error(w, fmt.Sprintf("index must be an integer between 0 and %d", len(index.sorts[0])-1), http.StatusBadRequest) + http.Error( + w, "index must be an integer between 0 and "+ + strconv.Itoa(int(rosa.PresetUnexportedStart-1)), + http.StatusBadRequest, + ) return } sort, err := strconv.Atoi(q.Get("sort")) if err != nil || sort >= len(index.sorts) || sort < 0 { - http.Error(w, fmt.Sprintf("sort must be an integer between 0 and %d", len(index.sorts)-1), http.StatusBadRequest) + http.Error( + w, "sort must be an integer between 0 and "+ + strconv.Itoa(sortOrderEnd), + http.StatusBadRequest, + ) return } values := index.sorts[sort][i:min(i+limit, len(index.sorts[sort]))]