-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenv.go
More file actions
30 lines (25 loc) · 690 Bytes
/
env.go
File metadata and controls
30 lines (25 loc) · 690 Bytes
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
package env
import (
"fmt"
"os"
)
// Set sets an environment variable.
func Set(key, value string) error {
return os.Setenv(key, value)
}
// Unset unsets an environment variable.
func Unset(key string) error {
return os.Unsetenv(key)
}
// Lookup returns the value of an environment variable and a boolean indicating
// whether the variable is present in the environment.
func Lookup(key string) (string, bool) {
return os.LookupEnv(key)
}
// Require checks if an environment variable is set and returns an error if it is not.
func Require(key string) error {
if _, ok := Lookup(key); !ok {
return fmt.Errorf("required environment variable %s is not set", key)
}
return nil
}