42 lines
649 B
Go
42 lines
649 B
Go
|
package env
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
"strconv"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func Get(name string, val string) string {
|
||
|
value := strings.TrimSpace(os.Getenv(name))
|
||
|
if value == "" {
|
||
|
return val
|
||
|
} else {
|
||
|
return value
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Integer(name string, val int64) int64 {
|
||
|
value := Get(name, "")
|
||
|
if n, err := strconv.ParseInt(value, 10, 64); err == nil {
|
||
|
return n
|
||
|
} else {
|
||
|
return val
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Float(name string, val float64) float64 {
|
||
|
value := Get(name, "")
|
||
|
if n, err := strconv.ParseFloat(value, 64); err == nil {
|
||
|
return n
|
||
|
} else {
|
||
|
return val
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func Set(name string, val string) {
|
||
|
value := os.Getenv(name)
|
||
|
if value == "" {
|
||
|
os.Setenv(name, val)
|
||
|
}
|
||
|
}
|