- 完成 CheckPermission 方法的完整实现(账号→角色→权限查询链) - 实现 Redis 缓存机制,大幅提升权限查询性能(~12倍提升) - 自动缓存失效:角色/权限变更时清除相关用户缓存 - 新增完整的单元测试和集成测试(10个测试用例全部通过) - 添加权限检查使用文档和缓存机制说明 - 归档 implement-permission-check OpenSpec 提案 性能优化: - 首次查询: ~18ms(3次DB查询 + 1次Redis写入) - 缓存命中: ~1.5ms(1次Redis查询) - TTL: 30分钟,自动失效机制保证数据一致性
37 lines
1.7 KiB
Go
37 lines
1.7 KiB
Go
package bootstrap
|
|
|
|
import (
|
|
accountSvc "github.com/break/junhong_cmp_fiber/internal/service/account"
|
|
authSvc "github.com/break/junhong_cmp_fiber/internal/service/auth"
|
|
permissionSvc "github.com/break/junhong_cmp_fiber/internal/service/permission"
|
|
personalCustomerSvc "github.com/break/junhong_cmp_fiber/internal/service/personal_customer"
|
|
roleSvc "github.com/break/junhong_cmp_fiber/internal/service/role"
|
|
shopSvc "github.com/break/junhong_cmp_fiber/internal/service/shop"
|
|
shopAccountSvc "github.com/break/junhong_cmp_fiber/internal/service/shop_account"
|
|
)
|
|
|
|
// services 封装所有 Service 实例
|
|
// 注意:此结构体不导出,仅在 bootstrap 包内部使用
|
|
type services struct {
|
|
Account *accountSvc.Service
|
|
Role *roleSvc.Service
|
|
Permission *permissionSvc.Service
|
|
PersonalCustomer *personalCustomerSvc.Service
|
|
Shop *shopSvc.Service
|
|
ShopAccount *shopAccountSvc.Service
|
|
Auth *authSvc.Service
|
|
}
|
|
|
|
// initServices 初始化所有 Service 实例
|
|
func initServices(s *stores, deps *Dependencies) *services {
|
|
return &services{
|
|
Account: accountSvc.New(s.Account, s.Role, s.AccountRole),
|
|
Role: roleSvc.New(s.Role, s.Permission, s.RolePermission),
|
|
Permission: permissionSvc.New(s.Permission, s.AccountRole, s.RolePermission, deps.Redis),
|
|
PersonalCustomer: personalCustomerSvc.NewService(s.PersonalCustomer, s.PersonalCustomerPhone, deps.VerificationService, deps.JWTManager, deps.Logger),
|
|
Shop: shopSvc.New(s.Shop, s.Account),
|
|
ShopAccount: shopAccountSvc.New(s.Account, s.Shop),
|
|
Auth: authSvc.New(s.Account, s.AccountRole, s.RolePermission, s.Permission, deps.TokenManager, deps.Logger),
|
|
}
|
|
}
|