refactor all service dependency injection
This commit is contained in:
29
module/base/logs/service/dependencies.go
Normal file
29
module/base/logs/service/dependencies.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"bsm/full/module/base/logs/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 contains shared infrastructure supplied by the all module.
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,13 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Expose(engine *gin.Engine) error {
|
||||
routers.Register("logs", engine)
|
||||
type ExposeOptions struct {
|
||||
Dependencies
|
||||
Engine *gin.Engine
|
||||
}
|
||||
|
||||
func Expose(options ExposeOptions) error {
|
||||
applyDependencies(options.Dependencies)
|
||||
routers.Register("logs", options.Engine)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user