From f70d53c75cfc429cca5878d43fb808d005a121a5 Mon Sep 17 00:00:00 2001 From: nquidox Date: Fri, 3 Apr 2026 11:45:22 +0300 Subject: [PATCH] uint16 type for port + env getter --- config/config.go | 6 +++--- config/helper.go | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index a4f88e4..79d9d1f 100644 --- a/config/config.go +++ b/config/config.go @@ -29,7 +29,7 @@ type TasksSource struct { type Rabbit struct { Host string - Port string + Port uint16 User string Pass string Vhost string @@ -40,7 +40,7 @@ func NewConfig() Config { App: App{ Mode: getEnv("APP_MODE", "dev"), LogLvl: getEnv("APP_LOG_LVL", "debug"), - CheckPeriod: getEnvSeconds("APP_CHECK_PERIOD_SECONDS", 20), + CheckPeriod: getEnvSeconds("APP_CHECK_PERIOD_SECONDS", 60*60*6), ProcChanLen: getEnvUint("APP_PROCESSOR_CHANNEL_SIZE", 100), }, @@ -57,7 +57,7 @@ func NewConfig() Config { Rabbit: Rabbit{ Host: getEnv("RABBIT_HOST", "10.0.0.4"), - Port: getEnv("RABBIT_PORT", "5672"), + Port: getEnvPort("RABBIT_PORT", 5672), User: getEnv("RABBIT_USER", "taskProcessorDev"), Pass: getEnv("RABBIT_PASS", "pass1234"), Vhost: getEnv("RABBIT_VHOST", "taskProcessorDevHost"), diff --git a/config/helper.go b/config/helper.go index e17dc02..1771dbe 100644 --- a/config/helper.go +++ b/config/helper.go @@ -39,3 +39,14 @@ func getEnvUint(key string, fallback uint) uint { } return fallback } + +func getEnvPort(key string, fallback uint16) uint16 { + if value, ok := os.LookupEnv(key); ok { + num, err := strconv.ParseUint(value, 10, 16) + if err != nil { + return fallback + } + return uint16(num) + } + return fallback +}