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

@@ -65,36 +65,37 @@ func NewSessionMiddleware(svc *iam.Service, cookieConfig securecookie.Config) fu
return
}
session, err := svc.SessionService.GetSession(ctx, sessionID)
if err != nil {
var (
errSessionNotFound *iam.ErrSessionNotFound
errSessionExpired *iam.ErrSessionExpired
)
session, err := svc.SessionService.GetSession(ctx, sessionID)
if err != nil {
if _, ok := errors.AsType[*iam.ErrSessionNotFound](err); ok {
securecookie.Clear(w, cookieConfig)
next.ServeHTTP(w, r)
if errors.As(err, &errSessionNotFound) || errors.As(err, &errSessionExpired) {
securecookie.Clear(w, cookieConfig)
next.ServeHTTP(w, r)
return
}
panic(fmt.Errorf("cannot get session: %w", err))
return
}
identity, err := svc.AccountService.GetIdentity(ctx, session.IdentityID)
if err != nil {
var errIdentityNotFound *iam.ErrIdentityNotFound
if errors.As(err, &errIdentityNotFound) {
securecookie.Clear(w, cookieConfig)
next.ServeHTTP(w, r)
if _, ok := errors.AsType[*iam.ErrSessionExpired](err); ok {
securecookie.Clear(w, cookieConfig)
next.ServeHTTP(w, r)
return
}
panic(fmt.Errorf("cannot get identity: %w", err))
return
}
panic(fmt.Errorf("cannot get session: %w", err))
}
identity, err := svc.AccountService.GetIdentity(ctx, session.IdentityID)
if err != nil {
if _, ok := errors.AsType[*iam.ErrIdentityNotFound](err); ok {
securecookie.Clear(w, cookieConfig)
next.ServeHTTP(w, r)
return
}
panic(fmt.Errorf("cannot get identity: %w", err))
}
userAgent := r.UserAgent()
// TODO: will work well when no layer 7 proxy is in front of the server
var ipAddress net.IP