models.go 696 B

123456789101112131415161718192021222324252627282930
  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&allowOldPasswords=true",
  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. }