mysql.go 409 B

12345678910111213141516171819202122232425
  1. package store
  2. import (
  3. "log"
  4. _ "github.com/go-sql-driver/mysql"
  5. "github.com/go-xorm/xorm"
  6. "github.com/710leo/urlooker/modules/web/g"
  7. )
  8. var Orm *xorm.Engine
  9. func InitMysql() {
  10. cfg := g.Config
  11. var err error
  12. Orm, err = xorm.NewEngine("mysql", cfg.Mysql.Addr)
  13. if err != nil {
  14. log.Fatalln("fail to connect mysql", err)
  15. }
  16. Orm.SetMaxIdleConns(cfg.Mysql.Idle)
  17. Orm.SetMaxOpenConns(cfg.Mysql.Max)
  18. }