-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathos.go
40 lines (31 loc) · 828 Bytes
/
os.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
// Copyright (c) 2020 Xelaj Software
//
// This file is a part of go-dry package.
// See https://github.com/xelaj/go-dry/blob/master/LICENSE for details
package dry
import (
"os"
"strings"
)
// EnvironMap returns the current environment variables as a map.
func EnvironMap() map[string]string {
return environToMap(os.Environ())
}
func environToMap(environ []string) map[string]string {
ret := make(map[string]string)
for _, v := range environ {
parts := strings.SplitN(v, "=", 2)
ret[parts[0]] = parts[1]
}
return ret
}
// GetenvDefault retrieves the value of the environment variable
// named by the key. It returns the given defaultValue if the
// variable is not present.
func GetenvDefault(key, defaultValue string) string {
ret := os.Getenv(key)
if ret == "" {
return defaultValue
}
return ret
}