V2
This commit is contained in:
55
V2/models/init.go
Normal file
55
V2/models/init.go
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* @Author: haodaquan
|
||||
* @Date: 2017-06-20 09:44:44
|
||||
* @Last Modified by: haodaquan
|
||||
* @Last Modified time: 2017-06-21 12:21:37
|
||||
*/
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
|
||||
"fmt"
|
||||
|
||||
"github.com/astaxie/beego"
|
||||
"github.com/astaxie/beego/orm"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
func Init() {
|
||||
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(Admin),
|
||||
new(Auth),
|
||||
new(Role),
|
||||
new(RoleAuth),
|
||||
new(ServerGroup),
|
||||
new(TaskServer),
|
||||
new(Ban),
|
||||
new(Group),
|
||||
new(Task),
|
||||
)
|
||||
|
||||
if beego.AppConfig.String("runmode") == "dev" {
|
||||
orm.Debug = true
|
||||
}
|
||||
}
|
||||
|
||||
func TableName(name string) string {
|
||||
return beego.AppConfig.String("db.prefix") + name
|
||||
}
|
||||
Reference in New Issue
Block a user