-
Notifications
You must be signed in to change notification settings - Fork 664
/
env.process.go
52 lines (46 loc) · 1.19 KB
/
env.process.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
50
51
52
package helper
import (
"errors"
"fmt"
"os"
"github.com/yaoapp/gou/process"
)
// ProcessEnvGet xiang.helper.EnvGet 读取ENV
func ProcessEnvGet(process *process.Process) interface{} {
process.ValidateArgNums(1)
name := process.ArgsString(0)
return os.Getenv(name)
}
// ProcessEnvSet xiang.helper.EnvSet 设置ENV
func ProcessEnvSet(process *process.Process) interface{} {
process.ValidateArgNums(2)
name := process.ArgsString(0)
value := process.ArgsString(1)
return os.Setenv(name, value)
}
// ProcessEnvMultiGet xiang.helper.MultiGet 读取ENV
func ProcessEnvMultiGet(process *process.Process) interface{} {
process.ValidateArgNums(1)
res := map[string]string{}
for i := range process.Args {
name := fmt.Sprintf("%v", process.Args[i])
res[name] = os.Getenv(name)
}
return res
}
// ProcessEnvMultiSet xiang.helper.MultiSet 设置ENV
func ProcessEnvMultiSet(process *process.Process) interface{} {
process.ValidateArgNums(1)
envs := process.ArgsMap(0)
message := ""
for name, value := range envs {
err := os.Setenv(name, fmt.Sprintf("%v", value))
if err != nil {
message = message + ";" + err.Error()
}
}
if message != "" {
return errors.New(message)
}
return nil
}