First implementation
This commit is contained in:
30
vendor/github.com/cyrilix/robocar-base/cli/cli.go
generated
vendored
Normal file
30
vendor/github.com/cyrilix/robocar-base/cli/cli.go
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func SetDefaultValueFromEnv(value *string, key string, defaultValue string) {
|
||||
if os.Getenv(key) != "" {
|
||||
*value = os.Getenv(key)
|
||||
} else {
|
||||
*value = defaultValue
|
||||
}
|
||||
}
|
||||
func SetIntDefaultValueFromEnv(value *int, key string, defaultValue int) error {
|
||||
var sVal string
|
||||
if os.Getenv(key) != "" {
|
||||
sVal = os.Getenv(key)
|
||||
val, err := strconv.Atoi(sVal)
|
||||
if err != nil {
|
||||
log.Printf("unable to convert string to int: %v", err)
|
||||
return err
|
||||
}
|
||||
*value = val
|
||||
} else {
|
||||
*value = defaultValue
|
||||
}
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user