move commit to job

This commit is contained in:
Victor Vieux
2013-12-13 14:19:56 -08:00
parent aaa1c48d24
commit 930ec9f52c
5 changed files with 71 additions and 25 deletions
+15 -7
View File
@@ -1,17 +1,16 @@
package engine
import (
"strings"
"io"
"encoding/json"
"strconv"
"bytes"
"encoding/json"
"fmt"
"io"
"strconv"
"strings"
)
type Env []string
func (env *Env) Get(key string) (value string) {
// FIXME: use Map()
for _, kv := range *env {
@@ -44,7 +43,6 @@ func (env *Env) GetBool(key string) (value bool) {
return true
}
func (env *Env) SetBool(key string, value bool) {
if value {
env.Set(key, "1")
@@ -79,6 +77,17 @@ func (env *Env) GetList(key string) []string {
return l
}
func (env *Env) GetJson(key string) interface{} {
sval := env.Get(key)
if sval == "" {
return nil
}
var m interface{}
//Discard error on purpose
json.Unmarshal([]byte(sval), &m)
return m
}
func (env *Env) SetJson(key string, value interface{}) error {
sval, err := json.Marshal(value)
if err != nil {
@@ -218,4 +227,3 @@ func (env *Env) Map() map[string]string {
}
return m
}
+4
View File
@@ -126,6 +126,10 @@ func (job *Job) GetenvList(key string) []string {
return job.env.GetList(key)
}
func (job *Job) GetenvJson(key string) interface{} {
return job.env.GetJson(key)
}
func (job *Job) SetenvJson(key string, value interface{}) error {
return job.env.SetJson(key, value)
}