rts-sim-testing-service/db/db.go

29 lines
446 B
Go
Raw Permalink Normal View History

package db
import (
"errors"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"joylink.club/bj-rtsts-server/config"
)
var DB *gorm.DB
func InitDb() error {
dsn := config.Config.Datasource.Dsn
if dsn == "" {
return errors.New("未设置数据库连接dsn")
}
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
})
if err != nil {
return err
}
DB = db
return nil
}