models.go 695 B

12345678910111213141516171819202122232425262728293031
  1. package models
  2. import (
  3. "fmt"
  4. "log"
  5. "../pkg/setting"
  6. "../routers/restful"
  7. "github.com/xormplus/xorm"
  8. )
  9. var Engine *xorm.Engine
  10. func Setup() {
  11. var err error
  12. // restful 接口的 数据库初始化
  13. if err := restful.SQLInit("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=True&loc=Local",
  14. setting.DatabaseSetting.User,
  15. setting.DatabaseSetting.Password,
  16. setting.DatabaseSetting.Host,
  17. setting.DatabaseSetting.Name), 1000, 10, setting.DatabaseSetting.ShowXormlog); err != nil {
  18. log.Fatal(err.Error())
  19. fmt.Println("dbs 数据库初始化失败 ")
  20. }
  21. Engine = restful.Engine
  22. Engine.ShowSQL(true)
  23. if err != nil {
  24. log.Fatalf("models.Setup err: %v", err)
  25. }
  26. }