This commit is contained in:
nquidox 2026-04-03 13:02:10 +03:00
commit 6a9de539ce
9 changed files with 277 additions and 0 deletions

52
config/helper.go Normal file
View file

@ -0,0 +1,52 @@
package config
import (
log "github.com/sirupsen/logrus"
"os"
"strconv"
"time"
)
func getEnv(key, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}
func getEnvSeconds(key string, fallback int) time.Duration {
if value, ok := os.LookupEnv(key); ok {
num, err := strconv.Atoi(value)
if err != nil {
log.Printf("Error converting %v to int, using default value - 60 seconds", key)
return time.Duration(60) * time.Second
}
return time.Duration(num) * time.Second
}
return time.Duration(fallback) * time.Second
}
func getEnvUint(key string, fallback uint) uint {
var def uint = 100
if value, ok := os.LookupEnv(key); ok {
num, err := strconv.ParseUint(value, 10, 64)
if err != nil {
log.Printf("Error converting %v to uint, using default value - %v", key, def)
return def
}
return uint(num)
}
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
}