AnthoLume/config/config.go

51 lines
1.2 KiB
Go
Raw Normal View History

2023-09-18 23:57:18 +00:00
package config
import (
"os"
"strings"
2023-09-18 23:57:18 +00:00
)
type Config struct {
// Server Config
Version string
ListenPort string
// DB Configuration
2023-09-18 23:57:18 +00:00
DBType string
DBName string
// Data Paths
2023-09-18 23:57:18 +00:00
ConfigPath string
DataPath string
// Miscellaneous Settings
RegistrationEnabled bool
CookieSessionKey string
2023-10-07 01:25:56 +00:00
SearchEnabled bool
2023-09-18 23:57:18 +00:00
}
func Load() *Config {
return &Config{
Version: "0.0.2",
DBType: trimLowerString(getEnv("DATABASE_TYPE", "SQLite")),
DBName: trimLowerString(getEnv("DATABASE_NAME", "book_manager")),
ConfigPath: getEnv("CONFIG_PATH", "/config"),
DataPath: getEnv("DATA_PATH", "/data"),
ListenPort: getEnv("LISTEN_PORT", "8585"),
CookieSessionKey: trimLowerString(getEnv("COOKIE_SESSION_KEY", "")),
RegistrationEnabled: trimLowerString(getEnv("REGISTRATION_ENABLED", "false")) == "true",
2023-10-07 01:25:56 +00:00
SearchEnabled: trimLowerString(getEnv("SEARCH_ENABLED", "false")) == "true",
2023-09-18 23:57:18 +00:00
}
}
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}
func trimLowerString(val string) string {
return strings.ToLower(strings.TrimSpace(val))
}