Initial commit: VPN panel on Go, PostgreSQL 17, Docker, Xray-core
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
AppPort int
|
||||
AppDomain string
|
||||
DatabaseURL string
|
||||
SecretKey string
|
||||
Installed bool
|
||||
}
|
||||
|
||||
func Load() (*Config, error) {
|
||||
port, _ := strconv.Atoi(getEnv("APP_PORT", "8080"))
|
||||
cfg := &Config{
|
||||
AppPort: port,
|
||||
AppDomain: getEnv("APP_DOMAIN", "localhost"),
|
||||
DatabaseURL: os.Getenv("DATABASE_URL"),
|
||||
SecretKey: getEnv("SECRET_KEY", ""),
|
||||
Installed: getEnv("INSTALLED", "false") == "true",
|
||||
}
|
||||
if cfg.DatabaseURL == "" {
|
||||
return nil, fmt.Errorf("DATABASE_URL не задан")
|
||||
}
|
||||
if cfg.SecretKey == "" {
|
||||
return nil, fmt.Errorf("SECRET_KEY не задан")
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func getEnv(key, fallback string) string {
|
||||
if v := os.Getenv(key); v != "" {
|
||||
return v
|
||||
}
|
||||
return fallback
|
||||
}
|
||||
Reference in New Issue
Block a user