增加mysql配置
This commit is contained in:
+3
-4
@@ -28,11 +28,10 @@ func InitDB(cfg *config.Config) *gorm.DB {
|
||||
|
||||
switch cfg.Database.Type {
|
||||
case "mysql":
|
||||
dsn := cfg.Database.DSN
|
||||
if dsn == "" {
|
||||
dsn = "root:password@tcp(127.0.0.1:3306)/blog_go?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
if cfg.Database.DSN == "" {
|
||||
log.Fatalf("Database DSN is required when type is 'mysql'. Please set it in your config file.")
|
||||
}
|
||||
dialector = mysql.Open(dsn)
|
||||
dialector = mysql.Open(cfg.Database.DSN)
|
||||
default:
|
||||
dbPath := filepath.Join(cfg.Path, "blog.db")
|
||||
dialector = sqlite.Open(dbPath)
|
||||
|
||||
Reference in New Issue
Block a user