package initial import ( "github.com/astaxie/beego" "net/url" "github.com/astaxie/beego/orm" ) func InitSql() { dbhost := beego.AppConfig.String("db.host") dbport := beego.AppConfig.String("db.port") dbuser := beego.AppConfig.String("db.user") dbpassword := beego.AppConfig.String("db.password") dbname := beego.AppConfig.String("db.name") timezone := beego.AppConfig.String("db.timezone") if dbport == "" { dbport = "3306" } dsn := dbuser + ":" + dbpassword + "@tcp(" + dbhost + ":" + dbport + ")/" + dbname + "?charset=utf8" // fmt.Println(dsn) if timezone != "" { dsn = dsn + "&loc=" + url.QueryEscape(timezone) } orm.RegisterDataBase("default", "mysql", dsn) //orm.RegisterModel(new(backgroundm.Auth), new(backgroundm.Role), new(backgroundm.RoleAuth), new(backgroundm.Admin), // new(backgroundm.Group), new(backgroundm.Env), new(backgroundm.Code), new(backgroundm.ApiSource), new(backgroundm.ApiDetail), // new(backgroundm.ApiPublic), // new(backgroundm.Template),new(commonm.PropertyNotice), // new(frontm.User), //) if beego.AppConfig.String("runmode") == "dev" { orm.Debug = true } }