1af9cc198f8d4b2ca2f40253750e6e8eb5a046c7.svn-base 411 B

1234567891011121314151617181920212223
  1. package dao
  2. import (
  3. "fmt"
  4. _ "github.com/go-sql-driver/mysql"
  5. "github.com/jinzhu/gorm"
  6. "log"
  7. )
  8. var db *gorm.DB
  9. func InitMysql(host, port, user, password, dbName string) (err error) {
  10. db, err = gorm.Open("mysql", fmt.Sprintf("%s:%s@(%s:%s)/%s?charset=utf8&parseTime=True&loc=Local", user, password, host, port, dbName))
  11. if err != nil{
  12. log.Println(err)
  13. return
  14. }
  15. db.SingularTable(true)
  16. return
  17. }