youtu_grpc/app/auth_service/internal/svc/service_context.go
2025-02-07 15:18:26 +08:00

39 lines
909 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package svc
import (
"context"
"gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/internal/config"
cli2 "gitea.youtukeji.com.cn/xiabin/youtu_grpc/app/auth_service/pkg"
redisCache "github.com/silenceper/wechat/v2/cache"
)
type ServiceContext struct {
Config config.Config
Cli cli2.Helper
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
}
}
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 cli2.DWClient
switch v.Type {
case cli2.DouyinClientType:
c = cli2.NewDouYinApi(v.AppId, v.AppSecret, dwCache)
case cli2.WechatClientType:
c = cli2.NewWechatApi(v.AppId, v.AppSecret, dwCache)
default:
continue
}
svc.Cli.Set(v.AppId, c)
}
}