12345678910111213141516171819202122232425262728293031 |
- 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",
- 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
- Engine.ShowSQL(true)
- if err != nil {
- log.Fatalf("models.Setup err: %v", err)
- }
- }
|