-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment.go
49 lines (41 loc) · 915 Bytes
/
environment.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
42
43
44
45
46
47
48
49
package service
import (
"fmt"
"os"
"strings"
)
func ParseEnvironment() (env map[string]string) {
rawEnv := os.Environ()
for _, rawVar := range rawEnv {
envVar := strings.Split(rawVar, "=")
env[envVar[0]] = envVar[1]
}
return env
}
type EnvVar struct {
Key string
Value string
}
func (p *Process) Environment() (env []string) {
for eKey, eValue := range p.Env {
env = append(env, fmt.Sprintf("%s=%s", eKey, eValue))
}
return env
}
func (p *Process) AppendEnvVar(envKey, envValue string) *Process {
p.Env[envKey] = envValue
return p
}
func (p *Process) ParseEnvironment() (env map[string]string) {
rawEnv := os.Environ()
for _, rawVar := range rawEnv {
envVar := strings.Split(rawVar, "=")
env[envVar[0]] = envVar[1]
}
p.Env = env
return p.Env
}
func (p *Process) IsRunning() bool {
// TODO: Is there really no better way to handle this?
return os.Getenv("_DAEMON") == "1"
}