-
Notifications
You must be signed in to change notification settings - Fork 0
/
gonv_main_test.go
41 lines (32 loc) · 1.15 KB
/
gonv_main_test.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
package gonv_test
import(
"fmt"
"github.com/jenazads/gonv"
)
func Example_manageEnvironmentalVariables()(){
// using system environmental variables
gonv.SetEnv("BOOL", true)
isBool, _ := gonv.GetBoolEnv("BOOL")
username, _:= gonv.GetEnv("USER") // return $USER system variable
fmt.Println(username, ", ", isBool)
gonv.SetEnv("NAME", "Jenazads")
nameSystem ,_ := gonv.GetEnv("NAME")
fmt.Println("name:", nameSystem)
gonv.UpdateEnv("NAME", 4)
nameUpdatedsystem, _ := gonv.GetIntEnv("NAME")
fmt.Println("name updated:", nameUpdatedsystem)
// using object environmental variables
gonvObject := gonv.NewGonv()
gonvObject.SetEnv("BOOL", true)
isBool, _ = gonvObject.GetBoolEnv("BOOL")
usernameObj,_ := gonvObject.GetEnv("USER") // return nil
fmt.Println(usernameObj, ", ", isBool)
gonvObject.SetEnv("NAME", "Jenazads")
nameLocal, _ := gonvObject.GetEnv("NAME")
fmt.Println("name:", nameLocal)
fmt.Println(gonvObject)
gonvObject.UpdateEnv("NAME", 4)
nameLocal, _ = gonv.GetIntEnv("NAME") // we can set another type because is interface type !
fmt.Println("name updated:", nameLocal)
fmt.Println(gonvObject)
}