package models import ( "fmt" "time" "tmr-watch/conf/setting" "tmr-watch/http/handle/restful" "github.com/xormplus/xorm" ) var Engine *xorm.Engine func Setup() { // restful 接口的 数据库初始化 sqlDNS := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=True&loc=Local", setting.DatabaseSetting.User, setting.DatabaseSetting.Password, setting.DatabaseSetting.Host, setting.DatabaseSetting.Name, ) if err := restful.SQLInit(setting.DatabaseSetting.Type, sqlDNS, 1000, 10, setting.DatabaseSetting.ShowXormlog); err != nil { panic(err) } Engine = restful.Engine Engine.SetConnMaxLifetime(time.Second * 30) Engine.ShowSQL(setting.DatabaseSetting.ShowXormlog) if err := Engine.Ping(); err != nil { panic(err) } }