重构core包

This commit is contained in:
2025-10-26 15:48:38 +08:00
parent 6a8e8f1f7d
commit 40eb57ee47
6 changed files with 444 additions and 333 deletions

View File

@@ -43,7 +43,7 @@ type API struct {
engine *gin.Engine // Gin 引擎实例,用于处理 HTTP 请求
logger *logs.Logger // 日志记录器,用于输出日志信息
userRepo repository.UserRepository // 用户数据仓库接口,用于用户数据操作
tokenService token.TokenService // Token 服务接口,用于 JWT token 的生成和解析
tokenService token.Service // Token 服务接口,用于 JWT token 的生成和解析
auditService audit.Service // 审计服务,用于记录用户操作
httpServer *http.Server // 标准库的 HTTP 服务器实例,用于启动和停止服务
config config.ServerConfig // API 服务器的配置,使用 infra/config 包中的 ServerConfig
@@ -69,7 +69,7 @@ func NewAPI(cfg config.ServerConfig,
pigFarmService service.PigFarmService,
pigBatchService service.PigBatchService,
monitorService service.MonitorService,
tokenService token.TokenService,
tokenService token.Service,
auditService audit.Service,
notifyService domain_notify.Service,
deviceService domain_device.Service,

View File

@@ -20,7 +20,7 @@ import (
type Controller struct {
userRepo repository.UserRepository
monitorService service.MonitorService
tokenService token.TokenService
tokenService token.Service
notifyService domain_notify.Service
logger *logs.Logger
}
@@ -30,7 +30,7 @@ func NewController(
userRepo repository.UserRepository,
monitorService service.MonitorService,
logger *logs.Logger,
tokenService token.TokenService,
tokenService token.Service,
notifyService domain_notify.Service,
) *Controller {
return &Controller{

View File

@@ -14,7 +14,7 @@ import (
// AuthMiddleware 创建一个Gin中间件用于JWT身份验证
// 它依赖于 TokenService 来解析和验证 token并使用 UserRepository 来获取完整的用户信息
func AuthMiddleware(tokenService token.TokenService, userRepo repository.UserRepository) gin.HandlerFunc {
func AuthMiddleware(tokenService token.Service, userRepo repository.UserRepository) gin.HandlerFunc {
return func(c *gin.Context) {
// 从 Authorization header 获取 token
authHeader := c.GetHeader("Authorization")