Enforce Go style rules across codebase

Apply five style rules: convert iota string enums to typed
string constants, replace errors.As with errors.AsType,
merge three-group imports into two groups, fix multiline
parameter/argument formatting, and replace fmt.Sprintf URL
construction with net/url.

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-05-20 11:46:39 +04:00
parent 34c25c2727
commit f5703d390b
105 changed files with 1180 additions and 940 deletions

View File

@@ -62,32 +62,31 @@ func NewAPIKeyMiddleware(svc *iam.Service, tokenSecret string) func(next http.Ha
return
}
apiKey, err := svc.APIKeyService.GetAPIKey(ctx, keyID)
if err != nil {
var (
errPersonalAPIKeyNotFound *iam.ErrPersonalAPIKeyNotFound
errPersonalAPIKeyExpired *iam.ErrPersonalAPIKeyExpired
)
if errors.As(err, &errPersonalAPIKeyNotFound) || errors.As(err, &errPersonalAPIKeyExpired) {
next.ServeHTTP(w, r)
return
}
panic(fmt.Errorf("cannot get personal API key: %w", err))
apiKey, err := svc.APIKeyService.GetAPIKey(ctx, keyID)
if err != nil {
if _, ok := errors.AsType[*iam.ErrPersonalAPIKeyNotFound](err); ok {
next.ServeHTTP(w, r)
return
}
identity, err := svc.AccountService.GetIdentity(ctx, apiKey.IdentityID)
if err != nil {
var errIdentityNotFound *iam.ErrIdentityNotFound
if errors.As(err, &errIdentityNotFound) {
next.ServeHTTP(w, r)
return
}
panic(fmt.Errorf("cannot get identity: %w", err))
if _, ok := errors.AsType[*iam.ErrPersonalAPIKeyExpired](err); ok {
next.ServeHTTP(w, r)
return
}
panic(fmt.Errorf("cannot get personal API key: %w", err))
}
identity, err := svc.AccountService.GetIdentity(ctx, apiKey.IdentityID)
if err != nil {
if _, ok := errors.AsType[*iam.ErrIdentityNotFound](err); ok {
next.ServeHTTP(w, r)
return
}
panic(fmt.Errorf("cannot get identity: %w", err))
}
ctx = ContextWithAPIKey(ctx, apiKey)
ctx = ContextWithIdentity(ctx, identity)