fix: address remaining golangci-lint warnings
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
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:
parent
675f765cc0
commit
12c547d215
@ -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
|
||||
}
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -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, `<!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) {
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user