45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
type Config struct {
|
|
Port string
|
|
APIToken string
|
|
PermanentWhitelistFile string
|
|
DataDir string
|
|
CleanupInterval time.Duration
|
|
WatchInterval time.Duration
|
|
DBPath string
|
|
}
|
|
|
|
func loadConfig() Config {
|
|
return Config{
|
|
Port: getEnv("AUTH_GATE_PORT", "8080"),
|
|
APIToken: getEnv("AUTH_GATE_API_TOKEN", ""),
|
|
PermanentWhitelistFile: getEnv("PERMANENT_WHITELIST_FILE", "./config/permanent_whitelist.txt"),
|
|
DataDir: getEnv("DATA_DIR", ". /data"),
|
|
CleanupInterval: parseDuration("CLEANUP_INTERVAL", 60*time.Second),
|
|
WatchInterval: parseDuration("WATCH_INTERVAL", 30*time.Second),
|
|
DBPath: getEnv("AUTH_GATE_DB_PATH", ". /data/auth-gate.db"),
|
|
}
|
|
}
|
|
|
|
func getEnv(key, defaultValue string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return defaultValue
|
|
}
|
|
|
|
func parseDuration(key string, defaultVal time.Duration) time.Duration {
|
|
if v := os.Getenv(key); v != "" {
|
|
d, err := time.ParseDuration(v)
|
|
if err == nil {
|
|
return d
|
|
}
|
|
}
|
|
return defaultVal
|
|
} |