-
Notifications
You must be signed in to change notification settings - Fork 7
/
options.go
51 lines (39 loc) · 924 Bytes
/
options.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2016 Nevio Vesic
// Please check out LICENSE file for more information about limitations
// MIT License
package main
import (
"os"
"strconv"
)
// OptionString - Will return ENV value back based on provided name casted as string
func OptionString(name, def string) string {
if res := os.Getenv(name); res != "" {
return string(res)
}
return def
}
// OptionBool - Will return ENV value back based on provided name casted as bool
func OptionBool(name string, def bool) bool {
var res string
if res = os.Getenv(name); res == "" {
return def
}
b, err := strconv.ParseBool(res)
if err != nil {
return def
}
return b
}
// OptionInt - Will return ENV value back based on provided name casted as int64
func OptionInt(name string, def int) int {
var res string
if res = os.Getenv(name); res == "" {
return def
}
b, err := strconv.Atoi(res)
if err != nil {
return def
}
return b
}