File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -61,3 +61,46 @@ func ExampleIsNotExist() {
61
61
// Output:
62
62
// file does not exist
63
63
}
64
+
65
+ func init () {
66
+ os .Setenv ("USER" , "gopher" )
67
+ os .Setenv ("HOME" , "/usr/gopher" )
68
+ os .Unsetenv ("GOPATH" )
69
+ }
70
+
71
+ func ExampleExpandEnv () {
72
+ fmt .Println (os .ExpandEnv ("$USER lives in ${HOME}." ))
73
+
74
+ // Output:
75
+ // gopher lives in /usr/gopher.
76
+ }
77
+
78
+ func ExampleLookupEnv () {
79
+ show := func (key string ) {
80
+ val , ok := os .LookupEnv (key )
81
+ if ! ok {
82
+ fmt .Printf ("%s not set\n " , key )
83
+ } else {
84
+ fmt .Printf ("%s=%s\n " , key , val )
85
+ }
86
+ }
87
+
88
+ show ("USER" )
89
+ show ("GOPATH" )
90
+
91
+ // Output:
92
+ // USER=gopher
93
+ // GOPATH not set
94
+ }
95
+
96
+ func ExampleGetenv () {
97
+ fmt .Printf ("%s lives in %s.\n " , os .Getenv ("USER" ), os .Getenv ("HOME" ))
98
+
99
+ // Output:
100
+ // gopher lives in /usr/gopher.
101
+ }
102
+
103
+ func ExampleUnsetenv () {
104
+ os .Setenv ("TMPDIR" , "/my/tmp" )
105
+ defer os .Unsetenv ("TMPDIR" )
106
+ }
You can’t perform that action at this time.
0 commit comments