From 25c974f0b57eb09d1e04c1b3dc78356e6bb96a17 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sun, 30 Dec 2018 20:43:51 +0100 Subject: [PATCH] envconst: support for int64 --- util/envconst/envconst.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/util/envconst/envconst.go b/util/envconst/envconst.go index 8159aae..8c13190 100644 --- a/util/envconst/envconst.go +++ b/util/envconst/envconst.go @@ -2,6 +2,7 @@ package envconst import ( "os" + "strconv" "sync" "time" ) @@ -23,3 +24,19 @@ func Duration(varname string, def time.Duration) time.Duration { cache.Store(varname, d) return d } + +func Int64(varname string, def int64) int64 { + if v, ok := cache.Load(varname); ok { + return v.(int64) + } + e := os.Getenv(varname) + if e == "" { + return def + } + d, err := strconv.ParseInt(e, 10, 64) + if err != nil { + panic(err) + } + cache.Store(varname, d) + return d +}