34 lines
920 B
Go
34 lines
920 B
Go
package svc
|
|
|
|
import (
|
|
"github.com/redis/go-redis/v9"
|
|
"github.com/saas-mingyang/mingyang-admin-common/i18n"
|
|
"github.com/zeromicro/go-zero/rest"
|
|
"github.com/zeromicro/go-zero/zrpc"
|
|
"mingyang-admin-app-api/internal/config"
|
|
i18n2 "mingyang-admin-app-api/internal/i18n"
|
|
"mingyang-admin-app-api/internal/middleware"
|
|
"mingyang-admin-app-rpc/appclient"
|
|
)
|
|
|
|
type ServiceContext struct {
|
|
Config config.Config
|
|
Trans *i18n.Translator
|
|
Authority rest.Middleware
|
|
AppRpc appclient.App
|
|
Redis redis.UniversalClient
|
|
}
|
|
|
|
func NewServiceContext(c config.Config) *ServiceContext {
|
|
trans := i18n.NewTranslator(c.I18nConf, i18n2.LocaleFS)
|
|
appRpc := appclient.NewApp(zrpc.NewClientIfEnable(c.AppRpc))
|
|
rds := c.RedisConf.MustNewUniversalRedis()
|
|
return &ServiceContext{
|
|
Authority: middleware.NewAuthorityMiddleware(appRpc, rds).Handle,
|
|
Config: c,
|
|
Redis: rds,
|
|
Trans: trans,
|
|
AppRpc: appRpc,
|
|
}
|
|
}
|