mirror of
https://github.com/zrepl/zrepl.git
synced 2025-06-23 11:11:40 +02:00
envconst: support for int64
This commit is contained in:
parent
ea719f5b5a
commit
25c974f0b5
@ -2,6 +2,7 @@ package envconst
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -23,3 +24,19 @@ func Duration(varname string, def time.Duration) time.Duration {
|
|||||||
cache.Store(varname, d)
|
cache.Store(varname, d)
|
||||||
return 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
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user