models.go 672 B

1234567891011121314151617181920212223242526272829
  1. package models
  2. import (
  3. "fmt"
  4. "../pkg/setting"
  5. "../routers/restful"
  6. "log"
  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. if err != nil {
  23. log.Fatalf("models.Setup err: %v", err)
  24. }
  25. }