common.go 263 B

12345678910111213141516171819
  1. package dao
  2. import (
  3. "fmt"
  4. _ "github.com/go-sql-driver/mysql"
  5. "github.com/jinzhu/gorm"
  6. )
  7. var Db *gorm.DB
  8. func InitDB(db *gorm.DB) {
  9. Db = db
  10. err := Db.AutoMigrate(
  11. &User{},
  12. ).Error
  13. if err != nil {
  14. panic(fmt.Sprintf("AutoMigrate err : %v", err))
  15. }
  16. }