fix: make lint

This commit is contained in:
zhr 2026-10-21 16:25:04 +08:00
parent 844f00da73
commit ec9d89be17
7 changed files with 45 additions and 16 deletions

View File

@ -0,0 +1,7 @@
# 2026-10-21 变动清单
## Session: 编译 / lint 修复
- **bootstrap**:将 `finishApp` 中 TCP/HTTP 装配抽到 `attachTransports`,满足 `funlen`;参数类型使用 `tcp.TaskPool`、`session.Manager` 接口。
- **client/logic**:`service_test.go` 中 `rangeValCopy` 改为索引遍历。
- **验证**:`make test` pass(golangci-lint + `go test ./...` + logic coverage ≥65%)。

View File

@ -221,6 +221,21 @@ func finishApp(cfg *Config, log *zap.Logger, logClose func() error, idgen *id.Ge
music := wireMusic(cfg, db, objects) music := wireMusic(cfg, db, objects)
users.BindAccountCleanup(jwtSvc, sessions, accountCleaners(friends, moments, square, groups, favorites, inbox, mailbox, chat)...) users.BindAccountCleanup(jwtSvc, sessions, accountCleaners(friends, moments, square, groups, favorites, inbox, mailbox, chat)...)
adminSvc, adminTokens := wireAdmin(cfg, db, groups, idgen, users) adminSvc, adminTokens := wireAdmin(cfg, db, groups, idgen, users)
attachTransports(app, cfg, log, pool, sessions, tlsConf, idgen, jwtSvc, authLimit, messages, syncSvc,
login, smsSvc, users, friends, groups, files, favorites, moments, square, music, client, adminSvc, adminTokens, moderation, probe)
return app, nil
}
func attachTransports(
app *App, cfg *Config, log *zap.Logger, pool tcp.TaskPool, sessions session.Manager, tlsConf *tls.Config,
idgen *id.Generator, jwtSvc *authlogic.JWT, authLimit *ratelimit.Limiter,
messages *msglogic.Service, syncSvc *synclogic.Service,
login *authlogic.LoginService, smsSvc *smslogic.Service, users *userlogic.Service,
friends *friendlogic.Service, groups *grouplogic.Service, files *uploadlogic.Service,
favorites *favlogic.Service, moments *momentlogic.Service, square *squarelogic.Service,
music *musiclogic.Service, client *clientlogic.Service,
adminSvc *adminlogic.Service, adminTokens *adminlogic.TokenService, moderation *modlogic.Service, probe *Probe,
) {
app.tcp = tcp.NewServer(log, pool, sessions, &tcp.Options{ app.tcp = tcp.NewServer(log, pool, sessions, &tcp.Options{
Addr: cfg.Server.TCP.Addr, Addr: cfg.Server.TCP.Addr,
Multicore: cfg.Server.TCP.Multicore, Multicore: cfg.Server.TCP.Multicore,
@ -241,9 +256,9 @@ func finishApp(cfg *Config, log *zap.Logger, logClose func() error, idgen *id.Ge
Sync: syncSvc, Sync: syncSvc,
}) })
app.http = httpx.New(log, cfg.Server.HTTP.Addr, httpEngineDeps( app.http = httpx.New(log, cfg.Server.HTTP.Addr, httpEngineDeps(
jwtSvc, login, smsSvc, users, friends, groups, files, favorites, moments, square, music, client, messages, syncSvc, adminSvc, adminTokens, moderation, probe, authLimit, jwtSvc, login, smsSvc, users, friends, groups, files, favorites, moments, square, music, client,
messages, syncSvc, adminSvc, adminTokens, moderation, probe, authLimit,
)) ))
return app, nil
} }
func httpEngineDeps( func httpEngineDeps(

View File

@ -32,7 +32,8 @@ func filterPlansByPlatform(items []entity.SubscriptionPlan, platform string) []e
} }
exact := make([]entity.SubscriptionPlan, 0, len(items)) exact := make([]entity.SubscriptionPlan, 0, len(items))
fallback := make([]entity.SubscriptionPlan, 0, len(items)) fallback := make([]entity.SubscriptionPlan, 0, len(items))
for _, p := range items { for i := range items {
p := items[i]
got := normalizePlatform(p.Platform) got := normalizePlatform(p.Platform)
if got == platform { if got == platform {
exact = append(exact, p) exact = append(exact, p)

View File

@ -84,7 +84,8 @@ func (s *stubClientRepo) ListPlans(_ context.Context, lang, packageName string)
} }
exact := make([]entity.SubscriptionPlan, 0) exact := make([]entity.SubscriptionPlan, 0)
fallback := make([]entity.SubscriptionPlan, 0) fallback := make([]entity.SubscriptionPlan, 0)
for _, p := range out { for i := range out {
p := out[i]
if p.PackageName == packageName { if p.PackageName == packageName {
exact = append(exact, p) exact = append(exact, p)
} else if p.PackageName == "" { } else if p.PackageName == "" {

View File

@ -221,9 +221,9 @@ func filterPlansByPackage(items []entity.SubscriptionPlan, packageName string) [
if packageName == "" { if packageName == "" {
// 无包名:仅返回默认兜底,避免多包混在一起 // 无包名:仅返回默认兜底,避免多包混在一起
out := make([]entity.SubscriptionPlan, 0, len(items)) out := make([]entity.SubscriptionPlan, 0, len(items))
for _, p := range items { for i := range items {
if strings.TrimSpace(p.PackageName) == "" { if strings.TrimSpace(items[i].PackageName) == "" {
out = append(out, p) out = append(out, items[i])
} }
} }
if len(out) > 0 { if len(out) > 0 {
@ -234,9 +234,10 @@ func filterPlansByPackage(items []entity.SubscriptionPlan, packageName string) [
want := strings.ToLower(entity.CanonicalHealthPackage(packageName)) want := strings.ToLower(entity.CanonicalHealthPackage(packageName))
exact := make([]entity.SubscriptionPlan, 0) exact := make([]entity.SubscriptionPlan, 0)
fallback := make([]entity.SubscriptionPlan, 0) fallback := make([]entity.SubscriptionPlan, 0)
for _, p := range items { for i := range items {
p := items[i]
pkg := entity.CanonicalHealthPackage(p.PackageName) pkg := entity.CanonicalHealthPackage(p.PackageName)
if pkg != "" && strings.ToLower(pkg) == want { if pkg != "" && strings.EqualFold(pkg, want) {
exact = append(exact, p) exact = append(exact, p)
} else if pkg == "" { } else if pkg == "" {
fallback = append(fallback, p) fallback = append(fallback, p)

View File

@ -108,7 +108,8 @@ func (m *Repo) DialogFaces(ctx context.Context, viewerID int64, conversationIDs
if err != nil { if err != nil {
return nil, mapDBErr(err) return nil, mapDBErr(err)
} }
for _, row := range rows { for i := range rows {
row := rows[i]
face := entity.DialogFace{ face := entity.DialogFace{
ConversationID: row.ID, Type: entity.Type(row.Type), ConversationID: row.ID, Type: entity.Type(row.Type),
GroupID: row.GroupID, LastReadMsgID: row.LastReadMsgID, GroupID: row.GroupID, LastReadMsgID: row.LastReadMsgID,

View File

@ -178,7 +178,8 @@ func (s *Service) PlaylistGrouped(ctx context.Context, parentID int64) (*entity.
return nil, err return nil, err
} }
groups := make([]entity.PlaylistGroup, 0, len(leaves)) groups := make([]entity.PlaylistGroup, 0, len(leaves))
for _, cat := range leaves { for i := range leaves {
cat := leaves[i]
items, err := s.repo.ListEnabledByCategory(ctx, cat.ID) items, err := s.repo.ListEnabledByCategory(ctx, cat.ID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -202,9 +203,9 @@ func filterRequireMember(items []entity.Track, requireMember *bool) []entity.Tra
} }
out := make([]entity.Track, 0, len(items)) out := make([]entity.Track, 0, len(items))
want := *requireMember want := *requireMember
for _, t := range items { for i := range items {
if t.RequireMember == want { if items[i].RequireMember == want {
out = append(out, t) out = append(out, items[i])
} }
} }
return out return out
@ -226,7 +227,8 @@ func collectLeafCategories(tree []entity.Category, parentID int64) []entity.Cate
} }
func findCategory(tree []entity.Category, id int64) (entity.Category, bool) { func findCategory(tree []entity.Category, id int64) (entity.Category, bool) {
for _, c := range tree { for i := range tree {
c := tree[i]
if c.ID == id { if c.ID == id {
return c, true return c, true
} }
@ -239,7 +241,8 @@ func findCategory(tree []entity.Category, id int64) (entity.Category, bool) {
func leafCategories(tree []entity.Category) []entity.Category { func leafCategories(tree []entity.Category) []entity.Category {
var out []entity.Category var out []entity.Category
for _, c := range tree { for i := range tree {
c := tree[i]
if len(c.Children) == 0 { if len(c.Children) == 0 {
out = append(out, c) out = append(out, c)
continue continue