fix version 1
This commit is contained in:
32
module/social/group/service/dependencies.go
Normal file
32
module/social/group/service/dependencies.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bsm/full/module/social/group/internal/impl"
|
||||
"git.apinb.com/bsm-sdk/core/cache/redis"
|
||||
cache "github.com/patrickmn/go-cache"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Dependencies 聚合宿主注入的共享基础设施
|
||||
type Dependencies struct {
|
||||
Redis *redis.RedisClient
|
||||
Etcd *clientv3.Client
|
||||
DB *gorm.DB
|
||||
Cache *cache.Cache
|
||||
}
|
||||
|
||||
func applyDependencies(deps Dependencies) {
|
||||
if deps.Redis != nil {
|
||||
impl.RedisService = deps.Redis
|
||||
}
|
||||
if deps.Etcd != nil {
|
||||
impl.EtcdService = deps.Etcd
|
||||
}
|
||||
if deps.DB != nil {
|
||||
impl.DBService = deps.DB
|
||||
}
|
||||
if deps.Cache != nil {
|
||||
impl.MemorySerice = deps.Cache
|
||||
}
|
||||
}
|
||||
26
module/social/group/service/expose.go
Normal file
26
module/social/group/service/expose.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"bsm/full/module/social/group/internal/server"
|
||||
gwRuntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type ExposeOptions struct {
|
||||
Dependencies
|
||||
GRPC *grpc.Server
|
||||
Gateway *gwRuntime.ServeMux
|
||||
}
|
||||
|
||||
// Expose 供聚合宿主接入:注册 gRPC service 与网关路由
|
||||
func Expose(options ExposeOptions) error {
|
||||
applyDependencies(options.Dependencies)
|
||||
server.New(options.GRPC)
|
||||
|
||||
if options.Gateway == nil {
|
||||
return nil
|
||||
}
|
||||
return server.RegisterGateway(context.Background(), options.Gateway)
|
||||
}
|
||||
Reference in New Issue
Block a user