Files

33 lines
819 B
Go

package svc
import (
"sundynix-micro-go/app/auth/api/internal/config"
"sundynix-micro-go/app/system/rpc/systemservice"
"sundynix-micro-go/common/utils/captcha"
"github.com/redis/go-redis/v9"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/zrpc"
)
type ServiceContext struct {
Config config.Config
SystemRpc systemservice.SystemService
}
func NewServiceContext(c config.Config) *ServiceContext {
// 初始化 Redis 并注入验证码存储
rdb := redis.NewClient(&redis.Options{
Addr: c.Redis.Host,
Password: c.Redis.Pass,
DB: c.Redis.DB,
})
captcha.InitWithRedis(rdb)
logx.Infof("验证码存储已切换至 Redis (DB%d)", c.Redis.DB)
return &ServiceContext{
Config: c,
SystemRpc: systemservice.NewSystemService(zrpc.MustNewClient(c.SystemRpc)),
}
}