43 lines
906 B
Go
43 lines
906 B
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
type Config struct {
|
|
Host string
|
|
Port int
|
|
SocketPath string
|
|
HeartbeatIntervalSec int
|
|
HeartbeatWaitSec int
|
|
}
|
|
|
|
func Load() Config {
|
|
return Config{
|
|
Host: getenv("ALT_API_HOST", "127.0.0.1"),
|
|
Port: getenvInt("ALT_API_PORT", 8080),
|
|
SocketPath: getenv("ALT_API_SOCKET_PATH", "/socket"),
|
|
HeartbeatIntervalSec: getenvInt("ALT_SOCKET_HEARTBEAT_INTERVAL_SEC", 30),
|
|
HeartbeatWaitSec: getenvInt("ALT_SOCKET_HEARTBEAT_WAIT_SEC", 10),
|
|
}
|
|
}
|
|
|
|
func getenv(key, fallback string) string {
|
|
if value := os.Getenv(key); value != "" {
|
|
return value
|
|
}
|
|
return fallback
|
|
}
|
|
|
|
func getenvInt(key string, fallback int) int {
|
|
value := os.Getenv(key)
|
|
if value == "" {
|
|
return fallback
|
|
}
|
|
parsed, err := strconv.Atoi(value)
|
|
if err != nil {
|
|
return fallback
|
|
}
|
|
return parsed
|
|
}
|