fix: address remaining golangci-lint warnings
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

- 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 <noreply@paperclip.ing>
This commit is contained in:
Head of Product & Engineering 2026-04-05 21:33:03 +02:00
parent 675f765cc0
commit 12c547d215
4 changed files with 8 additions and 4 deletions

View File

@ -69,8 +69,8 @@ func (c *Client) SendSMS(ctx context.Context, to, message string) (*SendResponse
continue continue
} }
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body) data, err := io.ReadAll(resp.Body)
resp.Body.Close()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -45,7 +45,10 @@ func (c *APIClient) UpdateMessageStatus(ctx context.Context, accessToken, messag
return err return err
} }
defer resp.Body.Close() 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 { if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("ghl update status returned %d: %s", resp.StatusCode, string(respBody)) return fmt.Errorf("ghl update status returned %d: %s", resp.StatusCode, string(respBody))

View File

@ -109,7 +109,7 @@ func (h *OAuthHandler) HandleCallback(w http.ResponseWriter, r *http.Request) {
slog.Info("ghl oauth install complete", "location_id", tokenResp.LocationID) slog.Info("ghl oauth install complete", "location_id", tokenResp.LocationID)
w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
fmt.Fprint(w, `<!DOCTYPE html><html><body><h2>Cast SMS installed successfully!</h2><p>You can close this tab.</p></body></html>`) _, _ = fmt.Fprint(w, `<!DOCTYPE html><html><body><h2>Cast SMS installed successfully!</h2><p>You can close this tab.</p></body></html>`)
} }
func (h *OAuthHandler) RefreshToken(ctx context.Context, locationID string) (*store.TokenRecord, error) { func (h *OAuthHandler) RefreshToken(ctx context.Context, locationID string) (*store.TokenRecord, error) {

View File

@ -7,6 +7,7 @@ import (
) )
var nonDigit = regexp.MustCompile(`[^\d]`) var nonDigit = regexp.MustCompile(`[^\d]`)
var e164Pattern = regexp.MustCompile(`^\+63\d{10}$`)
// ToLocal converts a phone number to Philippine local format (09XXXXXXXXX). // ToLocal converts a phone number to Philippine local format (09XXXXXXXXX).
func ToLocal(e164 string) (string, error) { func ToLocal(e164 string) (string, error) {
@ -63,7 +64,7 @@ func ToE164(local string) (string, error) {
return "", errors.New("invalid Philippine phone number") 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 "", errors.New("invalid Philippine phone number")
} }
return e164, nil return e164, nil