1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

improve GetenvJson

This commit is contained in:
Victor Vieux 2013-12-13 15:01:54 -08:00
parent 4b5ceb0f24
commit d5f5ecb658
3 changed files with 9 additions and 12 deletions

View file

@ -77,15 +77,12 @@ func (env *Env) GetList(key string) []string {
return l return l
} }
func (env *Env) GetJson(key string) interface{} { func (env *Env) GetJson(key string, iface interface{}) error {
sval := env.Get(key) sval := env.Get(key)
if sval == "" { if sval == "" {
return nil return nil
} }
var m interface{} return json.Unmarshal([]byte(sval), iface)
//Discard error on purpose
json.Unmarshal([]byte(sval), &m)
return m
} }
func (env *Env) SetJson(key string, value interface{}) error { func (env *Env) SetJson(key string, value interface{}) error {

View file

@ -126,8 +126,8 @@ func (job *Job) GetenvList(key string) []string {
return job.env.GetList(key) return job.env.GetList(key)
} }
func (job *Job) GetenvJson(key string) interface{} { func (job *Job) GetenvJson(key string, iface interface{}) error {
return job.env.GetJson(key) return job.env.GetJson(key, iface)
} }
func (job *Job) SetenvJson(key string, value interface{}) error { func (job *Job) SetenvJson(key string, value interface{}) error {

View file

@ -785,13 +785,13 @@ func (srv *Server) ContainerCommit(job *engine.Job) engine.Status {
job.Errorf("No such container: %s", name) job.Errorf("No such container: %s", name)
return engine.StatusErr return engine.StatusErr
} }
var config *Config var config Config
iConfig, ok := job.GetenvJson("config").(Config) if err := job.GetenvJson("config", &config); err != nil {
if ok { job.Error(err)
config = &iConfig return engine.StatusErr
} }
img, err := srv.runtime.Commit(container, job.Getenv("repo"), job.Getenv("tag"), job.Getenv("comment"), job.Getenv("author"), config) img, err := srv.runtime.Commit(container, job.Getenv("repo"), job.Getenv("tag"), job.Getenv("comment"), job.Getenv("author"), &config)
if err != nil { if err != nil {
job.Error(err) job.Error(err)
return engine.StatusErr return engine.StatusErr