+ ENV
This commit is contained in:
parent
a8e9a55c9a
commit
9c936cab4c
3 changed files with 40 additions and 0 deletions
22
helper/env.process.go
Normal file
22
helper/env.process.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package helper
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/yaoapp/gou"
|
||||
)
|
||||
|
||||
// ProcessEnvGet xiang.helper.EnvGet 读取ENV
|
||||
func ProcessEnvGet(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(1)
|
||||
name := process.ArgsString(0)
|
||||
return os.Getenv(name)
|
||||
}
|
||||
|
||||
// ProcessEnvSet xiang.helper.EnvSet 设置ENV
|
||||
func ProcessEnvSet(process *gou.Process) interface{} {
|
||||
process.ValidateArgNums(2)
|
||||
name := process.ArgsString(0)
|
||||
value := process.ArgsString(1)
|
||||
return os.Setenv(name, value)
|
||||
}
|
||||
15
helper/env_test.go
Normal file
15
helper/env_test.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package helper
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/yaoapp/gou"
|
||||
)
|
||||
|
||||
func TestProcessEnv(t *testing.T) {
|
||||
err := gou.NewProcess("xiang.helper.EnvSet", "XIANG_UNIT_TEST", "FOO").Run()
|
||||
assert.Nil(t, err)
|
||||
test := gou.NewProcess("xiang.helper.EnvGet", "XIANG_UNIT_TEST").Run().(string)
|
||||
assert.Equal(t, "FOO", test)
|
||||
}
|
||||
|
|
@ -33,6 +33,9 @@ func init() {
|
|||
gou.RegisterProcessHandler("xiang.helper.Case", ProcessCase)
|
||||
gou.RegisterProcessHandler("xiang.helper.IF", ProcessIF)
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.EnvSet", ProcessEnvSet)
|
||||
gou.RegisterProcessHandler("xiang.helper.EnvGet", ProcessEnvGet)
|
||||
|
||||
gou.RegisterProcessHandler("xiang.helper.Print", ProcessPrint)
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue