From 12c547d2159324207223646bb5990f46f05dd283 Mon Sep 17 00:00:00 2001 From: Head of Product & Engineering Date: Sun, 5 Apr 2026 21:33:03 +0200 Subject: [PATCH] fix: address remaining golangci-lint warnings - internal/ghl/oauth.go: acknowledge fmt.Fprint return (errcheck) - internal/ghl/api.go: handle io.ReadAll error instead of discarding (errcheck) - internal/cast/client.go: replace defer-in-loop with explicit Body.Close after ReadAll (gocritic defer-in-loop) - internal/phone/normalize.go: move inline regexp.MustCompile to package-level var e164Pattern (gocritic / performance) Co-Authored-By: Paperclip --- internal/cast/client.go | 2 +- internal/ghl/api.go | 5 ++++- internal/ghl/oauth.go | 2 +- internal/phone/normalize.go | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/cast/client.go b/internal/cast/client.go index ce083ca..e19b035 100644 --- a/internal/cast/client.go +++ b/internal/cast/client.go @@ -69,8 +69,8 @@ func (c *Client) SendSMS(ctx context.Context, to, message string) (*SendResponse continue } - defer resp.Body.Close() data, err := io.ReadAll(resp.Body) + resp.Body.Close() if err != nil { return nil, err } diff --git a/internal/ghl/api.go b/internal/ghl/api.go index ff160e7..a710fa8 100644 --- a/internal/ghl/api.go +++ b/internal/ghl/api.go @@ -45,7 +45,10 @@ func (c *APIClient) UpdateMessageStatus(ctx context.Context, accessToken, messag return err } defer resp.Body.Close() - respBody, _ := io.ReadAll(resp.Body) + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return fmt.Errorf("ghl update status: failed to read response body: %w", err) + } if resp.StatusCode < 200 || resp.StatusCode >= 300 { return fmt.Errorf("ghl update status returned %d: %s", resp.StatusCode, string(respBody)) diff --git a/internal/ghl/oauth.go b/internal/ghl/oauth.go index a2f15c9..a0d73f1 100644 --- a/internal/ghl/oauth.go +++ b/internal/ghl/oauth.go @@ -109,7 +109,7 @@ func (h *OAuthHandler) HandleCallback(w http.ResponseWriter, r *http.Request) { slog.Info("ghl oauth install complete", "location_id", tokenResp.LocationID) w.Header().Set("Content-Type", "text/html; charset=utf-8") w.WriteHeader(http.StatusOK) - fmt.Fprint(w, `

Cast SMS installed successfully!

You can close this tab.

`) + _, _ = fmt.Fprint(w, `

Cast SMS installed successfully!

You can close this tab.

`) } func (h *OAuthHandler) RefreshToken(ctx context.Context, locationID string) (*store.TokenRecord, error) { diff --git a/internal/phone/normalize.go b/internal/phone/normalize.go index f3ac507..9677934 100644 --- a/internal/phone/normalize.go +++ b/internal/phone/normalize.go @@ -7,6 +7,7 @@ import ( ) var nonDigit = regexp.MustCompile(`[^\d]`) +var e164Pattern = regexp.MustCompile(`^\+63\d{10}$`) // ToLocal converts a phone number to Philippine local format (09XXXXXXXXX). func ToLocal(e164 string) (string, error) { @@ -63,7 +64,7 @@ func ToE164(local string) (string, error) { return "", errors.New("invalid Philippine phone number") } - if !regexp.MustCompile(`^\+63\d{10}$`).MatchString(e164) { + if !e164Pattern.MatchString(e164) { return "", errors.New("invalid Philippine phone number") } return e164, nil