feat: 添加数据库连接字符串环境变量支持

This commit is contained in:
tbphp
2025-06-30 16:26:10 +08:00
parent 731315144e
commit 5f0990f22b
2 changed files with 6 additions and 3 deletions

View File

@@ -15,8 +15,10 @@ import (
var DB *gorm.DB
func InitDB() (*gorm.DB, error) {
// TODO: 从配置中心读取DSN
dsn := "root:1236@tcp(127.0.0.1:3306)/gpt_load?charset=utf8mb4&parseTime=True&loc=Local"
dsn := os.Getenv("DATABASE_DSN")
if dsn == "" {
return nil, fmt.Errorf("DATABASE_DSN environment variable not set")
}
newLogger := logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer