From 3201c2bf8ec783dc201473a3e2857a90fcd64b2a Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Wed, 11 Oct 2023 15:51:17 +0300 Subject: [PATCH] feat: util load int32 env --- util/env.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/util/env.go b/util/env.go index c97907d..5a57019 100644 --- a/util/env.go +++ b/util/env.go @@ -26,6 +26,20 @@ func LoadEnvStr(key string, def string) string { return def } +func LoadEnvInt32(key string, def int32) int32 { + value, found := os.LookupEnv(key) + if found { + res, err := strconv.ParseInt(value, 10, 32) + if err != nil { + log.Fatalf("[erya] Environment variable %s failed to parse to int32 from '%s'", key, value) + } + return int32(res) + } + + log.Printf("[erya] Environment variable %s is empty, using default '%d'", key, def) + return def +} + func LoadEnvBool(key string, def bool) bool { value, found := os.LookupEnv(key) if found { -- 2.44.1