models.go 638 B

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