-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathenv.go
More file actions
38 lines (30 loc) · 885 Bytes
/
env.go
File metadata and controls
38 lines (30 loc) · 885 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
31
32
33
34
35
36
37
38
package sys
import (
"os"
)
// Env is an interface to a set of environment variables.
type Env interface {
// Get gets the environment variable of the given name.
Get(name string) string
}
type realEnv struct{}
func (r realEnv) Get(name string) string {
return os.Getenv(name)
}
// RealEnv returns an Env implementation that uses os.Getenv every time Get is called.
func RealEnv() Env {
return realEnv{}
}
// FakeEnv is an Env implementation that stores the environment in a map.
type FakeEnv struct {
// Envs is the map from which Get calls will look to retrieve environment variables.
Envs map[string]string
}
// NewFakeEnv returns a new FakeEnv with no values in Envs.
func NewFakeEnv() *FakeEnv {
return &FakeEnv{Envs: make(map[string]string)}
}
// Get is the Env interface implementation for Env.
func (f *FakeEnv) Get(name string) string {
return f.Envs[name]
}