refactor: move Go source files to src/ directory
Organize project structure by relocating all Go files to a src/ directory, following standard Go project conventions and improving code organization.
This commit is contained in:
41
src/config.go
Normal file
41
src/config.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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_PROXY_PORT", "8080"),
|
||||
APIToken: getEnv("AUTH_PROXY_API_TOKEN", ""),
|
||||
DataDir: getEnv("DATA_DIR", "/data"),
|
||||
CleanupInterval: parseDuration("CLEANUP_INTERVAL", 60*time.Second),
|
||||
DBPath: getEnv("AUTH_PROXY_DB_PATH", "/data/auth-proxy.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
|
||||
}
|
||||
Reference in New Issue
Block a user