package models import ( "fmt" "log" "../pkg/setting" "../routers/restful" "github.com/xormplus/xorm" ) var Engine *xorm.Engine func Setup() { var err error // restful 接口的 数据库初始化 if err := restful.SQLInit("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=True&loc=Local&allowOldPasswords=true", setting.DatabaseSetting.User, setting.DatabaseSetting.Password, setting.DatabaseSetting.Host, setting.DatabaseSetting.Name), 1000, 10, setting.DatabaseSetting.ShowXormlog); err != nil { log.Fatal(err.Error()) fmt.Println("dbs 数据库初始化失败 ") } Engine = restful.Engine if err != nil { log.Fatalf("models.Setup err: %v", err) } }