Skip to content

Commit

Permalink
fix fiber version
Browse files Browse the repository at this point in the history
  • Loading branch information
iesreza committed Nov 29, 2023
1 parent bba3930 commit fea8335
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
2 changes: 2 additions & 0 deletions evo.database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions evo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 2 additions & 5 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 2 additions & 7 deletions lib/settings/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{}
Expand Down
15 changes: 15 additions & 0 deletions lib/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 0 additions & 3 deletions lib/settings/yml/yml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit fea8335

Please sign in to comment.