-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcli.go
34 lines (30 loc) · 838 Bytes
/
cli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Package cli implements various reusable utility functions for command-line interfaces.
package cli
import (
"os"
"strconv"
)
// CheckErr panics if err is not nil
func CheckErr(err error) {
if err != nil {
panic(err)
}
}
// GetEnv returns the value of the environment variable named by key, or defaultValue if the environment variable doesn't exist
func GetEnv(key, defaultValue string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return defaultValue
}
// GetEnvInt returns the value of the environment variable named by key, or defaultValue if the environment variable
// doesn't exist or is not a valid integer
func GetEnvInt(key string, defaultValue int) int {
if value, ok := os.LookupEnv(key); ok {
val, err := strconv.Atoi(value)
if err == nil {
return val
}
}
return defaultValue
}