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
}
func (env *Env) GetJson(key string) interface{} {
func (env *Env) GetJson(key string, iface interface{}) error {
sval := env.Get(key)
if sval == "" {
return nil
}
var m interface{}
//Discard error on purpose
json.Unmarshal([]byte(sval), &m)
return m
return json.Unmarshal([]byte(sval), iface)
}
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)
}
func (job *Job) GetenvJson(key string) interface{} {
return job.env.GetJson(key)
func (job *Job) GetenvJson(key string, iface interface{}) error {
return job.env.GetJson(key, iface)
}
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)
return engine.StatusErr
}
var config *Config
iConfig, ok := job.GetenvJson("config").(Config)
if ok {
config = &iConfig
var config Config
if err := job.GetenvJson("config", &config); err != nil {
job.Error(err)
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 {
job.Error(err)
return engine.StatusErr