44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package config
|
|
|
|
import "os"
|
|
|
|
type Config struct {
|
|
AppEnv string
|
|
ServerHost string
|
|
ServerPort string
|
|
DatabasePath string
|
|
EncryptionKey string
|
|
ArtworkCacheDir string
|
|
MediaRoot string
|
|
CORSOrigins string
|
|
DefaultAdminUsername string
|
|
DefaultAdminPassword string
|
|
}
|
|
|
|
func Load() Config {
|
|
return Config{
|
|
AppEnv: getenv("APP_ENV", "development"),
|
|
ServerHost: getenv("SERVER_HOST", "0.0.0.0"),
|
|
ServerPort: getenv("SERVER_PORT", "5050"),
|
|
DatabasePath: getenv("DATABASE_PATH", "./data/app.db"),
|
|
EncryptionKey: getenv("APP_ENCRYPTION_KEY", "temporserv-dev-insecure-key"),
|
|
ArtworkCacheDir: getenv("ARTWORK_CACHE_DIR", "./data/artwork"),
|
|
MediaRoot: getenv("MEDIA_ROOT", "./media"),
|
|
CORSOrigins: getenv("CORS_ORIGINS", "http://localhost:5173"),
|
|
DefaultAdminUsername: getenv("DEFAULT_ADMIN_USERNAME", "demo"),
|
|
DefaultAdminPassword: getenv("DEFAULT_ADMIN_PASSWORD", "demo"),
|
|
}
|
|
}
|
|
|
|
func (c Config) Address() string {
|
|
return c.ServerHost + ":" + c.ServerPort
|
|
}
|
|
|
|
func getenv(key, fallback string) string {
|
|
value := os.Getenv(key)
|
|
if value == "" {
|
|
return fallback
|
|
}
|
|
return value
|
|
}
|