Files
nettopo-go/internal/config/config.go
T
2026-04-10 16:08:35 +10:00

57 lines
1.1 KiB
Go

package config
import (
"os"
"strings"
)
type Config struct {
HTTPAddr string
DBDSN string
StoreBackend string
RunMigrations bool
SNMPEnabled bool
SNMPCommunity string
ResetDBSecret string // NETTOPO_RESET_DB_SECRET — секрет для POST /api/admin/purge-scans
}
func FromEnv() Config {
addr := os.Getenv("HTTP_ADDR")
if addr == "" {
addr = ":8080"
}
dbDSN := os.Getenv("DB_DSN")
storeBackend := os.Getenv("STORE_BACKEND")
if storeBackend == "" {
if dbDSN != "" {
storeBackend = "postgres"
} else {
storeBackend = "memory"
}
}
runMigrations := true
if os.Getenv("RUN_MIGRATIONS") == "false" {
runMigrations = false
}
snmpEnabled := true
if os.Getenv("SNMP_ENABLED") == "false" {
snmpEnabled = false
}
snmpCommunity := os.Getenv("SNMP_COMMUNITY")
if snmpCommunity == "" {
snmpCommunity = "public"
}
return Config{
HTTPAddr: addr,
DBDSN: dbDSN,
StoreBackend: storeBackend,
RunMigrations: runMigrations,
SNMPEnabled: snmpEnabled,
SNMPCommunity: snmpCommunity,
ResetDBSecret: strings.TrimSpace(os.Getenv("NETTOPO_RESET_DB_SECRET")),
}
}