style: fix all golangci-lint issues and format code (refs #17)

Fix 380 lint violations across all Go source files including wsl_v5,
nlreturn, noinlineerr, errcheck, funlen, funcorder, tagliatelle,
perfsprint, modernize, revive, gosec, ireturn, mnd, forcetypeassert,
cyclop, and others.

Key changes:
- Split large handler/command functions into smaller methods
- Extract scan helpers for database queries
- Reorder exported/unexported methods per funcorder
- Add sentinel errors in models package
- Use camelCase JSON tags per tagliatelle defaults
- Add package comments
- Fix .gitignore to not exclude cmd/chat-cli directory
This commit is contained in:
clawbot
2026-02-26 06:27:56 -08:00
parent 636546d74a
commit b78d526f02
13 changed files with 1920 additions and 753 deletions

View File

@@ -2,7 +2,6 @@ package models
import (
"context"
"fmt"
"time"
)
@@ -23,5 +22,5 @@ func (t *AuthToken) User(ctx context.Context) (*User, error) {
return ul.GetUserByID(ctx, t.UserID)
}
return nil, fmt.Errorf("user lookup not available")
return nil, ErrUserLookupNotAvailable
}

View File

@@ -2,7 +2,6 @@ package models
import (
"context"
"fmt"
"time"
)
@@ -23,7 +22,7 @@ func (cm *ChannelMember) User(ctx context.Context) (*User, error) {
return ul.GetUserByID(ctx, cm.UserID)
}
return nil, fmt.Errorf("user lookup not available")
return nil, ErrUserLookupNotAvailable
}
// Channel returns the full Channel for this membership.
@@ -32,5 +31,5 @@ func (cm *ChannelMember) Channel(ctx context.Context) (*Channel, error) {
return cl.GetChannelByID(ctx, cm.ChannelID)
}
return nil, fmt.Errorf("channel lookup not available")
return nil, ErrChannelLookupNotAvailable
}

View File

@@ -6,6 +6,7 @@ package models
import (
"context"
"database/sql"
"errors"
)
// DB is the interface that models use to query the database.
@@ -24,6 +25,12 @@ type ChannelLookup interface {
GetChannelByID(ctx context.Context, id string) (*Channel, error)
}
// Sentinel errors for model lookup methods.
var (
ErrUserLookupNotAvailable = errors.New("user lookup not available")
ErrChannelLookupNotAvailable = errors.New("channel lookup not available")
)
// Base is embedded in all model structs to provide database access.
type Base struct {
db DB
@@ -40,7 +47,7 @@ func (b *Base) GetDB() *sql.DB {
}
// GetUserLookup returns the DB as a UserLookup if it implements the interface.
func (b *Base) GetUserLookup() UserLookup {
func (b *Base) GetUserLookup() UserLookup { //nolint:ireturn // interface return is intentional
if ul, ok := b.db.(UserLookup); ok {
return ul
}
@@ -49,7 +56,7 @@ func (b *Base) GetUserLookup() UserLookup {
}
// GetChannelLookup returns the DB as a ChannelLookup if it implements the interface.
func (b *Base) GetChannelLookup() ChannelLookup {
func (b *Base) GetChannelLookup() ChannelLookup { //nolint:ireturn // interface return is intentional
if cl, ok := b.db.(ChannelLookup); ok {
return cl
}

View File

@@ -2,7 +2,6 @@ package models
import (
"context"
"fmt"
"time"
)
@@ -23,5 +22,5 @@ func (s *Session) User(ctx context.Context) (*User, error) {
return ul.GetUserByID(ctx, s.UserID)
}
return nil, fmt.Errorf("user lookup not available")
return nil, ErrUserLookupNotAvailable
}