- Migrate IP-based temporary whitelisting from file to SQLite storage - Add REST API endpoints for managing temporary and permanent whitelists - Create `.env.example` with required environment variables - Document API endpoints in README.md and docs/api.md - Add new dependency `modernc.org/sqlite` for SQLite support - Update deployment and security documentation
42 lines
856 B
Go
42 lines
856 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
type Config struct {
|
|
Port string
|
|
APIToken string
|
|
DataDir string
|
|
CleanupInterval time.Duration
|
|
DBPath string
|
|
}
|
|
|
|
func loadConfig() Config {
|
|
return Config{
|
|
Port: getEnv("AUTH_GATE_PORT", "8080"),
|
|
APIToken: getEnv("AUTH_GATE_API_TOKEN", ""),
|
|
DataDir: getEnv("DATA_DIR", "/data"),
|
|
CleanupInterval: parseDuration("CLEANUP_INTERVAL", 60*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
|
|
}
|