chore: sync local updates
This commit is contained in:
25
mengyaping-backend/config/database.go
Normal file
25
mengyaping-backend/config/database.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// DatabaseConfig MySQL 连接(环境变量 DB_* 可覆盖;亦支持 DB_DSN 整串)
|
||||
type DatabaseConfig struct {
|
||||
Host string `json:"host"`
|
||||
Port string `json:"port"`
|
||||
User string `json:"user"`
|
||||
Password string `json:"password"`
|
||||
Database string `json:"database"`
|
||||
}
|
||||
|
||||
// DatabaseDSN 返回 GORM/MySQL driver 用连接串
|
||||
func (c *Config) DatabaseDSN() string {
|
||||
if dsn := os.Getenv("DB_DSN"); dsn != "" {
|
||||
return dsn
|
||||
}
|
||||
d := c.Database
|
||||
return fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local",
|
||||
d.User, d.Password, d.Host, d.Port, d.Database)
|
||||
}
|
||||
Reference in New Issue
Block a user