youtu_grpc/auth_service/internal/svc/service_context.go

39 lines
894 B
Go
Raw Normal View History

2025-02-05 18:45:49 +08:00
package svc
2025-02-06 15:35:23 +08:00
import (
"context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/auth_service/internal/config"
cli "gitea.youtukeji.com.cn/xiabin/youtu_grpc/auth_service/pkg"
redisCache "github.com/silenceper/wechat/v2/cache"
)
2025-02-05 18:45:49 +08:00
type ServiceContext struct {
Config config.Config
2025-02-06 15:35:23 +08:00
Cli cli.Helper
2025-02-05 18:45:49 +08:00
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
}
}
2025-02-06 15:35:23 +08:00
func (svc *ServiceContext) InitClient(c config.Config) {
dwCache := redisCache.NewRedis(context.Background(), &redisCache.RedisOpts{Host: c.Redis.Host})
//配置小程序cli抖音&微信)
for _, v := range c.AppData {
var c cli.DWClient
switch v.Type {
case cli.DouyinClientType:
c = cli.NewDouYinApi(v.AppId, v.AppSecret, dwCache)
case cli.WechatClientType:
c = cli.NewWechatApi(v.AppId, v.AppSecret, dwCache)
default:
continue
}
svc.Cli.Set(v.AppId, c)
}
}