mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-26 00:35:15 +00:00
util: add env var util functions
This commit is contained in:
parent
ec6c10a96a
commit
ecf888dfd6
38
pkg/util/envvars.go
Normal file
38
pkg/util/envvars.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func GetEnvVarInt(n string) (int, bool) {
|
||||
str, ok := os.LookupEnv(n)
|
||||
if !ok {
|
||||
return 0, false
|
||||
}
|
||||
|
||||
num, err := strconv.Atoi(str)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Errorf("can not parse env var %q as int, incorrect format", str)
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return num, true
|
||||
}
|
||||
|
||||
func GetEnvVarBool(n string) (bool, bool) {
|
||||
str, ok := os.LookupEnv(n)
|
||||
if !ok {
|
||||
return false, false
|
||||
}
|
||||
|
||||
num, err := strconv.ParseBool(str)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Errorf("can not parse env var %q as bool, incorrect format", str)
|
||||
return false, false
|
||||
}
|
||||
|
||||
return num, true
|
||||
}
|
Loading…
Reference in New Issue
Block a user