app-cloudep-portal-api-gateway/internal/svc/service_context.go

44 lines
1.4 KiB
Go
Raw Normal View History

2024-08-25 07:08:49 +00:00
package svc
import (
"app-cloudep-portal-api-gateway/internal/config"
2024-08-26 06:36:58 +00:00
"app-cloudep-portal-api-gateway/internal/middleware"
ers "code.30cm.net/digimon/library-go/errors"
"code.30cm.net/digimon/library-go/errors/code"
"github.com/zeromicro/go-zero/core/stores/redis"
"github.com/zeromicro/go-zero/zrpc"
accountRpc "code.30cm.net/digimon/proto-all/pkg/member"
notificationRpc "code.30cm.net/digimon/proto-all/pkg/notification"
permissionRpc "code.30cm.net/digimon/proto-all/pkg/permission"
2024-08-25 07:08:49 +00:00
)
type ServiceContext struct {
Config config.Config
2024-08-26 06:36:58 +00:00
AuthMiddleware *middleware.AuthMiddleware
AccountRpc accountRpc.AccountClient
TokenRpc permissionRpc.TokenServiceClient
NotificationRpc notificationRpc.SenderServiceClient
Redis redis.Redis
2024-08-25 07:08:49 +00:00
}
func NewServiceContext(c config.Config) *ServiceContext {
2024-08-26 06:36:58 +00:00
ers.Scope = code.CloudEPPortalGW
newRedis, err := redis.NewRedis(c.RedisCluster, redis.Cluster())
if err != nil {
panic(err)
}
2024-08-25 07:08:49 +00:00
return &ServiceContext{
2024-08-26 06:36:58 +00:00
Config: c,
AuthMiddleware: middleware.NewAuthMiddleware(),
AccountRpc: accountRpc.NewAccountClient(zrpc.MustNewClient(c.AccountRpc).Conn()),
TokenRpc: permissionRpc.NewTokenServiceClient(zrpc.MustNewClient(c.PermissionRpc).Conn()),
NotificationRpc: notificationRpc.NewSenderServiceClient(zrpc.MustNewClient(c.NotificationRpc).Conn()),
Redis: *newRedis,
2024-08-25 07:08:49 +00:00
}
}