gin不依赖配置

This commit is contained in:
2024-12-17 22:47:16 +08:00
parent 754e1ae43c
commit c2d44e5947
24 changed files with 1377 additions and 60 deletions

View File

@ -1,7 +1,5 @@
package lightCore
var ConfigValue = &Config{}
type Config struct {
App AppConfigModel `mapstructure:"app" yaml:"app"`
Server ServerConfigModel `mapstructure:"server" yaml:"server"`

View File

@ -1,21 +0,0 @@
package lightCore
import (
"code.zhecent.com/gopkg/light-core/pkg/myGorm"
"gorm.io/gorm"
)
var DBEngine *gorm.DB
func InitDB() {
orm := myGorm.NewSimpleORM(
ConfigValue.Database.User,
ConfigValue.Database.Password,
ConfigValue.Database.Host,
ConfigValue.Database.Name,
ConfigValue.Database.Charset,
ConfigValue.Server.RunMode,
)
orm.SetLoggerLevel(ConfigValue.Database.LogLevel)
DBEngine = orm.ConnectMysql()
}

View File

@ -1,11 +0,0 @@
package lightCore
import "gorm.io/gorm"
type GormAdapter struct {
*gorm.DB
}
func NewGormAdapter(db *gorm.DB) *GormAdapter {
return &GormAdapter{DB: db}
}

View File

@ -13,8 +13,8 @@ type LightCore struct {
props []interface{}
}
func StartEngine() *LightCore {
gin.SetMode(ConfigValue.Server.RunMode)
func StartEngine(runMode string) *LightCore {
gin.SetMode(runMode)
g := &LightCore{gin: gin.New(), props: make([]interface{}, 0)}
g.gin.Use(gin.Logger(), gin.Recovery())
return g
@ -23,8 +23,8 @@ func (t *LightCore) GetGin() *gin.Engine {
return t.gin
}
func (t *LightCore) Launch() {
err := t.gin.Run(fmt.Sprintf(":%d", ConfigValue.Server.HttpPort))
func (t *LightCore) Launch(port int) {
err := t.gin.Run(fmt.Sprintf(":%d", port))
if err != nil {
panic("Gin Launch Error")
}

View File

@ -26,8 +26,4 @@ func (t *Start) Start() {
panic("Server Config Error")
}
ConfigValue = t.config
//初始化数据库
InitDB()
}