main
lzf 2024-07-19 15:50:30 +08:00
commit 85d7510113
2 changed files with 4 additions and 30 deletions

View File

@ -1,25 +0,0 @@
package myconf
import (
"fmt"
"testing"
)
func TestConf(t *testing.T) {
type Config struct {
App struct {
Name string
Addr string
Port int
}
Redis struct {
Addr string
Db int
}
}
var config = &Config{}
Init("test.yaml", config)
fmt.Printf("%+v\n", config)
}

View File

@ -53,17 +53,16 @@ func DB(key ...string) *gorm.DB {
return instance
}
func InitDefault(config *Config) error {
return Init(DefaultKey, config)
func InitDefault(config *Config) {
Init(DefaultKey, config)
}
func Init(key string, config *Config) error {
func Init(key string, config *Config) {
db, err := New(config)
if err != nil {
return err
panic(err)
}
instanceMap[key] = db
return nil
}
func New(config *Config) (*gorm.DB, error) {