feat: major update - MySQL, chat, wishlist, PWA, admin overhaul
This commit is contained in:
@@ -9,8 +9,18 @@ import (
|
||||
type Config struct {
|
||||
AdminToken string `json:"adminToken"`
|
||||
AuthAPIURL string `json:"authApiUrl"`
|
||||
|
||||
// Database DSN. If empty, falls back to the test DB DSN.
|
||||
// Format: "user:pass@tcp(host:port)/dbname?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
DatabaseDSN string `json:"databaseDsn"`
|
||||
}
|
||||
|
||||
// Default DSNs for each environment.
|
||||
const (
|
||||
TestDSN = "mengyastore-test:mengyastore-test@tcp(10.1.1.100:3306)/mengyastore-test?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
ProdDSN = "mengyastore:mengyastore@tcp(192.168.1.100:3306)/mengyastore?charset=utf8mb4&parseTime=True&loc=Local"
|
||||
)
|
||||
|
||||
func Load(path string) (*Config, error) {
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
@@ -23,5 +33,12 @@ func Load(path string) (*Config, error) {
|
||||
if cfg.AdminToken == "" {
|
||||
cfg.AdminToken = "shumengya520"
|
||||
}
|
||||
// Default to test DB if not configured; environment variable overrides config file.
|
||||
if dsn := os.Getenv("DATABASE_DSN"); dsn != "" {
|
||||
cfg.DatabaseDSN = dsn
|
||||
}
|
||||
if cfg.DatabaseDSN == "" {
|
||||
cfg.DatabaseDSN = TestDSN
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user