From 3b7bf35bf3ee66010f6af2772084e652d6423b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=97=E5=AD=90?= Date: Sat, 12 Apr 2025 05:55:18 +0800 Subject: [PATCH] fix: lint --- internal/apps/memcached/app.go | 6 +++--- internal/service/helper.go | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/apps/memcached/app.go b/internal/apps/memcached/app.go index c96ccd52..e673caa9 100644 --- a/internal/apps/memcached/app.go +++ b/internal/apps/memcached/app.go @@ -34,7 +34,7 @@ func (s *App) Route(r chi.Router) { func (s *App) Load(w http.ResponseWriter, r *http.Request) { status, err := systemctl.Status("memcached") if err != nil { - service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get Memcached status: %v"), err) + service.Error(w, http.StatusInternalServerError, s.t.Get("failed to get Memcached status: %v", err)) return } if !status { @@ -53,7 +53,7 @@ func (s *App) Load(w http.ResponseWriter, r *http.Request) { _, err = conn.Write([]byte("stats\nquit\n")) if err != nil { - service.Error(w, http.StatusInternalServerError, s.t.Get("failed to write to Memcached: %v"), err) + service.Error(w, http.StatusInternalServerError, s.t.Get("failed to write to Memcached: %v", err)) return } @@ -74,7 +74,7 @@ func (s *App) Load(w http.ResponseWriter, r *http.Request) { } if err = scanner.Err(); err != nil { - service.Error(w, http.StatusInternalServerError, s.t.Get("failed to read from Memcached: %v"), err) + service.Error(w, http.StatusInternalServerError, s.t.Get("failed to read from Memcached: %v", err)) return } diff --git a/internal/service/helper.go b/internal/service/helper.go index 33cb6d12..d6873efc 100644 --- a/internal/service/helper.go +++ b/internal/service/helper.go @@ -39,8 +39,11 @@ func Error(w http.ResponseWriter, code int, format string, args ...any) { defer render.Release() render.Header(chix.HeaderContentType, chix.MIMEApplicationJSONCharsetUTF8) // must before Status() render.Status(code) + if len(args) > 0 { + format = fmt.Sprintf(format, args...) + } render.JSON(&ErrorResponse{ - Message: fmt.Sprintf(format, args...), + Message: format, }) }