为 9 个模块添加 Context 超时控制

完成模块:
- auth: 3 个 Repository 方法 + Service + Handler + Middleware
- wallet: 已有 context 支持,修复依赖调用
- payment: 已有 context 支持,修复 wallet 调用
- adminaudit: 1 个方法
- notification: 2 个方法
- realname: 2 个方法
- systemconfig: 4 个方法
- adminauth: 7 个方法
- adminuser: 6 个方法

所有数据库调用已改为 r.db.WithContext(ctx),完整传递 context 链路。

待完成模块: order, listing, chat 等 12 个模块(约 157 个方法)
This commit is contained in:
yml2213
2026-06-10 09:12:27 +08:00
parent c517349db6
commit b377f8350b
23 changed files with 174 additions and 159 deletions
+10 -9
View File
@@ -1,6 +1,7 @@
package adminauth
import (
"context"
"errors"
"hfb_sys/backend/internal/modules/auth"
@@ -23,7 +24,7 @@ func NewService(repo *Repository, jwt *auth.JWTManager) *Service {
return &Service{repo: repo, jwt: jwt}
}
func (s *Service) Refresh(refreshToken string) (*auth.TokenPair, error) {
func (s *Service) Refresh(ctx context.Context, refreshToken string) (*auth.TokenPair, error) {
if s.jwt == nil {
return nil, ErrDependencyUnavailable
}
@@ -38,33 +39,33 @@ func (s *Service) Refresh(refreshToken string) (*auth.TokenPair, error) {
return &pair, nil
}
func (s *Service) Captcha() (*CaptchaDTO, error) {
func (s *Service) Captcha(ctx context.Context, ) (*CaptchaDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
return s.repo.Captcha()
return s.repo.Captcha(ctx, )
}
func (s *Service) Login(username string, password string, captchaID string, captchaCode string) (LoginResult, error) {
func (s *Service) Login(ctx context.Context, username string, password string, captchaID string, captchaCode string) (LoginResult, error) {
if s.repo == nil {
return LoginResult{}, ErrDependencyUnavailable
}
if username == "" || password == "" || captchaID == "" || captchaCode == "" {
return LoginResult{}, ErrInvalidCredential
}
return s.repo.Login(username, password, captchaID, captchaCode)
return s.repo.Login(ctx, username, password, captchaID, captchaCode)
}
func (s *Service) Me(adminID uint64) (*AdminDTO, error) {
func (s *Service) Me(ctx context.Context, adminID uint64) (*AdminDTO, error) {
if s.repo == nil {
return nil, ErrDependencyUnavailable
}
return s.repo.FindByID(adminID)
return s.repo.FindByID(ctx, adminID)
}
func (s *Service) UpdateSupportStatus(adminID uint64, status string) error {
func (s *Service) UpdateSupportStatus(ctx context.Context, adminID uint64, status string) error {
if s.repo == nil {
return ErrDependencyUnavailable
}
return s.repo.UpdateSupportStatus(adminID, status)
return s.repo.UpdateSupportStatus(ctx, adminID, status)
}