1 Star 0 Fork 0

linxing/youye-core

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
provider.go 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
Mark 提交于 2024-01-29 17:39 . rename package
package sdk
import (
"fmt"
"gitee.com/linxing_3/youye-core/logger"
"gitee.com/linxing_3/youye-core/sdk/application"
"gitee.com/linxing_3/youye-core/sdk/config"
"gitee.com/linxing_3/youye-core/sdk/pkg/jwtauth"
"gitee.com/linxing_3/youye-core/storage"
"github.com/gin-gonic/gin"
"github.com/google/wire"
"gorm.io/gorm"
)
var Provider = wire.NewSet(
GetDefaultAppGorm,
GetCacheAdapte,
GetGinEngine,
GetLogger,
config.Provider,
)
func moduleUnregistErr(msg string) error {
return fmt.Errorf("%s not regist to app", msg)
}
func GetDefaultAppGorm(app application.IApplication) (*gorm.DB, error) {
db := app.GetDbByKey("*")
if db == nil {
return nil, moduleUnregistErr("gorm db")
}
return db, nil
}
func GetCacheAdapte(app application.IApplication) (storage.AdapterCache, error) {
adapter := app.GetCacheAdapter()
if adapter != nil {
return adapter, nil
}
return nil, moduleUnregistErr("cache adapter")
}
func GetGinEngine(app application.IApplication) (*gin.Engine, error) {
httpHandler := app.GetEngine()
switch h := httpHandler.(type) {
case *gin.Engine:
return h, nil
default:
return nil, moduleUnregistErr("gin engine")
}
}
func GetLogger(app application.IApplication) (logger.Logger, error) {
return app.GetLogger(), nil
}
func GetAuth(app application.IApplication) (jwtauth.IAuth, error) {
auth := app.GetAuth()
if auth != nil {
return auth, nil
}
return nil, moduleUnregistErr("auth")
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/linxing_3/youye-core.git
git@gitee.com:linxing_3/youye-core.git
linxing_3
youye-core
youye-core
v0.0.1-202403221058

搜索帮助