Fix all lint/build issues on main branch (closes #13)
- Resolve duplicate method declarations (CreateUser, GetUserByToken,
GetUserByNick) between db.go and queries.go by renaming queries.go
methods to CreateSimpleUser, LookupUserByToken, LookupUserByNick
- Fix 377 lint issues across all categories:
- nlreturn (107): Add blank lines before returns
- wsl_v5 (156): Add required whitespace
- noinlineerr (25): Use plain assignments instead of inline error handling
- errcheck (15): Check all error return values
- mnd (10): Extract magic numbers to named constants
- err113 (7): Use wrapped static errors instead of dynamic errors
- gosec (7): Fix SSRF, SQL injection warnings; add nolint for false positives
- modernize (7): Replace interface{} with any
- cyclop (2): Reduce cyclomatic complexity via command map dispatch
- gocognit (1): Break down complex handler into sub-handlers
- funlen (3): Extract long functions into smaller helpers
- funcorder (4): Reorder methods (exported before unexported)
- forcetypeassert (2): Add safe type assertions with ok checks
- ireturn (2): Replace interface-returning methods with concrete lookups
- noctx (3): Use NewRequestWithContext and ExecContext
- tagliatelle (5): Fix JSON tag casing to camelCase
- revive (4): Rename package from 'api' to 'chatapi'
- rowserrcheck (8): Add rows.Err() checks after iteration
- lll (2): Shorten long lines
- perfsprint (5): Use strconv and string concatenation
- nestif (2): Extract nested conditionals into helper methods
- wastedassign (1): Remove wasted assignments
- gosmopolitan (1): Add nolint for intentional Local() time display
- usestdlibvars (1): Use http.MethodGet
- godoclint (2): Remove duplicate package comments
- Fix broken migration 003_users.sql that conflicted with 002_schema.sql
(different column types causing test failures)
- All tests pass, make check reports 0 issues
This commit is contained in:
@@ -2,10 +2,13 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ErrUserLookupNotAvailable is returned when user lookup is not configured.
|
||||
var ErrUserLookupNotAvailable = errors.New("user lookup not available")
|
||||
|
||||
// AuthToken represents an authentication token for a user session.
|
||||
type AuthToken struct {
|
||||
Base
|
||||
@@ -19,9 +22,5 @@ type AuthToken struct {
|
||||
|
||||
// User returns the user who owns this token.
|
||||
func (t *AuthToken) User(ctx context.Context) (*User, error) {
|
||||
if ul := t.GetUserLookup(); ul != nil {
|
||||
return ul.GetUserByID(ctx, t.UserID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("user lookup not available")
|
||||
return t.LookupUser(ctx, t.UserID)
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ErrChannelLookupNotAvailable is returned when channel lookup is not configured.
|
||||
var ErrChannelLookupNotAvailable = errors.New("channel lookup not available")
|
||||
|
||||
// ChannelMember represents a user's membership in a channel.
|
||||
type ChannelMember struct {
|
||||
Base
|
||||
@@ -19,18 +22,10 @@ type ChannelMember struct {
|
||||
|
||||
// User returns the full User for this membership.
|
||||
func (cm *ChannelMember) User(ctx context.Context) (*User, error) {
|
||||
if ul := cm.GetUserLookup(); ul != nil {
|
||||
return ul.GetUserByID(ctx, cm.UserID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("user lookup not available")
|
||||
return cm.LookupUser(ctx, cm.UserID)
|
||||
}
|
||||
|
||||
// Channel returns the full Channel for this membership.
|
||||
func (cm *ChannelMember) Channel(ctx context.Context) (*Channel, error) {
|
||||
if cl := cm.GetChannelLookup(); cl != nil {
|
||||
return cl.GetChannelByID(ctx, cm.ChannelID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("channel lookup not available")
|
||||
return cm.LookupChannel(ctx, cm.ChannelID)
|
||||
}
|
||||
|
||||
@@ -39,20 +39,22 @@ func (b *Base) GetDB() *sql.DB {
|
||||
return b.db.GetDB()
|
||||
}
|
||||
|
||||
// GetUserLookup returns the DB as a UserLookup if it implements the interface.
|
||||
func (b *Base) GetUserLookup() UserLookup {
|
||||
if ul, ok := b.db.(UserLookup); ok {
|
||||
return ul
|
||||
// LookupUser looks up a user by ID if the database supports it.
|
||||
func (b *Base) LookupUser(ctx context.Context, id string) (*User, error) {
|
||||
ul, ok := b.db.(UserLookup)
|
||||
if !ok {
|
||||
return nil, ErrUserLookupNotAvailable
|
||||
}
|
||||
|
||||
return nil
|
||||
return ul.GetUserByID(ctx, id)
|
||||
}
|
||||
|
||||
// GetChannelLookup returns the DB as a ChannelLookup if it implements the interface.
|
||||
func (b *Base) GetChannelLookup() ChannelLookup {
|
||||
if cl, ok := b.db.(ChannelLookup); ok {
|
||||
return cl
|
||||
// LookupChannel looks up a channel by ID if the database supports it.
|
||||
func (b *Base) LookupChannel(ctx context.Context, id string) (*Channel, error) {
|
||||
cl, ok := b.db.(ChannelLookup)
|
||||
if !ok {
|
||||
return nil, ErrChannelLookupNotAvailable
|
||||
}
|
||||
|
||||
return nil
|
||||
return cl.GetChannelByID(ctx, id)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -19,9 +18,5 @@ type Session struct {
|
||||
|
||||
// User returns the user who owns this session.
|
||||
func (s *Session) User(ctx context.Context) (*User, error) {
|
||||
if ul := s.GetUserLookup(); ul != nil {
|
||||
return ul.GetUserByID(ctx, s.UserID)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("user lookup not available")
|
||||
return s.LookupUser(ctx, s.UserID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user