backend/pkg/orm/db.go

23 lines
320 B
Go
Raw Normal View History

2022-01-11 04:00:39 +08:00
package orm
import (
"fmt"
"git.icechen.cn/monorepo/backend/pkg/config"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
var DB *gorm.DB
func init() {
dsn, err := config.GetMysql()
if err != nil {
fmt.Println("init db error: ", err)
return
}
DB, err = gorm.Open(mysql.Open(dsn))
if err != nil {
panic(err)
}
}