uint16 type for port + env getter

This commit is contained in:
nquidox 2026-04-03 11:45:22 +03:00
parent 979c7c4a4f
commit f70d53c75c
2 changed files with 14 additions and 3 deletions

View file

@ -29,7 +29,7 @@ type TasksSource struct {
type Rabbit struct { type Rabbit struct {
Host string Host string
Port string Port uint16
User string User string
Pass string Pass string
Vhost string Vhost string
@ -40,7 +40,7 @@ func NewConfig() Config {
App: App{ App: App{
Mode: getEnv("APP_MODE", "dev"), Mode: getEnv("APP_MODE", "dev"),
LogLvl: getEnv("APP_LOG_LVL", "debug"), 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), ProcChanLen: getEnvUint("APP_PROCESSOR_CHANNEL_SIZE", 100),
}, },
@ -57,7 +57,7 @@ func NewConfig() Config {
Rabbit: Rabbit{ Rabbit: Rabbit{
Host: getEnv("RABBIT_HOST", "10.0.0.4"), Host: getEnv("RABBIT_HOST", "10.0.0.4"),
Port: getEnv("RABBIT_PORT", "5672"), Port: getEnvPort("RABBIT_PORT", 5672),
User: getEnv("RABBIT_USER", "taskProcessorDev"), User: getEnv("RABBIT_USER", "taskProcessorDev"),
Pass: getEnv("RABBIT_PASS", "pass1234"), Pass: getEnv("RABBIT_PASS", "pass1234"),
Vhost: getEnv("RABBIT_VHOST", "taskProcessorDevHost"), Vhost: getEnv("RABBIT_VHOST", "taskProcessorDevHost"),

View file

@ -39,3 +39,14 @@ func getEnvUint(key string, fallback uint) uint {
} }
return fallback 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
}