diff --git a/evo.database.go b/evo.database.go index ab11623e..60f6a3ee 100644 --- a/evo.database.go +++ b/evo.database.go @@ -20,7 +20,9 @@ var db *gorm.DB func setupDatabase() { var err error var config = DatabaseConfig{} + settings.Register("Database", &config) + settings.Get("Database").Cast(&config) if !config.Enabled { return } diff --git a/evo.go b/evo.go index 5fddad4a..68a34f35 100644 --- a/evo.go +++ b/evo.go @@ -24,14 +24,15 @@ func Setup() { log.Fatal(err) } settings.Register("HTTP", &http) - + settings.Get("HTTP").Cast(&http) err = generic.Parse(http).Cast(&fiberConfig) app = fiber.New(fiberConfig) if settings.Get("Database.Enabled").Bool() { - database.SetDBO(GetDBO()) - settings.SetDefaultDriver(database.Driver) + db = GetDBO() dbo.Register(db) + settings.SetDefaultDriver(database.Driver) + } cache.Register() diff --git a/example/main.go b/example/main.go index 52b84d45..bcf6cba6 100644 --- a/example/main.go +++ b/example/main.go @@ -3,15 +3,12 @@ package main import ( "fmt" "github.com/getevo/evo/v2" - "github.com/getevo/evo/v2/lib/log" + "github.com/getevo/evo/v2/lib/settings" ) func main() { evo.Setup() - log.SetLevel(log.NoticeLevel) - log.SetWriters(func(message string) { - - }) + fmt.Println(settings.Get("NATS.SERVER").String()) //var db = evo.GetDBO() /* var data = map[string]interface{}{} db.Raw("SELECT * FROM services").Scan(&data) diff --git a/lib/settings/database/database.go b/lib/settings/database/database.go index e7620fb9..a935ef5d 100644 --- a/lib/settings/database/database.go +++ b/lib/settings/database/database.go @@ -3,22 +3,17 @@ package database import ( "fmt" "github.com/getevo/evo/v2/lib/args" + "github.com/getevo/evo/v2/lib/db" "github.com/getevo/evo/v2/lib/generic" - "gorm.io/gorm" "gorm.io/gorm/clause" "strings" "sync" ) -var db *gorm.DB var Driver = &Database{} var domains = map[string]SettingDomain{} -func SetDBO(v *gorm.DB) { - db = v -} - type Database struct { mu sync.Mutex data map[string]map[string]generic.Value @@ -125,7 +120,7 @@ func (config *Database) Init(params ...string) error { config.mu.Lock() var items []Setting if args.Exists("-migrate") { - db.AutoMigrate(&Setting{}, &SettingDomain{}) + db.Unscoped().AutoMigrate(&Setting{}, &SettingDomain{}) } if config.data == nil { config.data = map[string]map[string]generic.Value{} diff --git a/lib/settings/settings.go b/lib/settings/settings.go index 923580d0..f6d8de74 100644 --- a/lib/settings/settings.go +++ b/lib/settings/settings.go @@ -112,6 +112,21 @@ func SetMulti(data map[string]interface{}) error { func Register(settings ...interface{}) { defaultDriver.Register(settings...) + /* var key = "" + for idx, _ := range settings { + var v = generic.Parse(settings[idx]) + if v.Is("string") { + key = v.String() + continue + } + if v.Is("settings.SettingDomain") || v.Is("settings.Setting") { + continue + } + c := Get(key) + if !c.IsEmpty() && !c.IsNil() { + c.Cast(v) + } + }*/ } func Init(params ...string) error { diff --git a/lib/settings/yml/yml.go b/lib/settings/yml/yml.go index 149409ac..9f277989 100644 --- a/lib/settings/yml/yml.go +++ b/lib/settings/yml/yml.go @@ -52,9 +52,6 @@ func (config *Yaml) SetMulti(data map[string]interface{}) error { return config.write() } func (config *Yaml) Register(settings ...interface{}) error { - if config.data == nil { - config.data = map[string]interface{}{} - } for _, s := range settings { var v = generic.Parse(s) if !v.Is("settings.Setting") {