backend/pkg/orm/db.go

23 lines
320 B
Go

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)
}
}