-
Notifications
You must be signed in to change notification settings - Fork 0
/
gonv_vars.go
53 lines (46 loc) · 1.18 KB
/
gonv_vars.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
52
53
package gonv
import(
"os";
"github.com/jenazads/goutils";
)
// Set new environmental variable
func SetEnv(tag string, value interface{}) error {
if val := os.Getenv(tag); val == ""{
err := os.Setenv(tag, goutils.ToString(value))
return err
}else{
return GonvErrAlreadyExist
}
}
// Get environmental variable
func GetEnv(tag string) (string, error) {
if val := os.Getenv(tag); val == ""{
return "", GonvErrNotFound
}else{
return val, nil
}
}
// Update environmental variable
func UpdateEnv(tag string, value interface{}) error {
if val := os.Getenv(tag); val == ""{
return GonvErrNotFound
}else{
err:=os.Setenv(tag, goutils.ToString(value))
return err
}
}
// Get environmental variable and transforms to string
func GetStringEnv(tag string) (string, error){
value, err := GetEnv(tag)
return goutils.ToString(value), err
}
// Get environmental variable and transforms to int
func GetIntEnv(tag string) (int, error){
value, err := GetEnv(tag)
return goutils.ToInt(value), err
}
// Get environmental variable and transforms to bool
func GetBoolEnv(tag string) (bool, error){
value, err := GetEnv(tag)
return goutils.ToBool(value), err
}