From 40d42a1aac9bac6c0a7a135bcf9c2699a5df9703 Mon Sep 17 00:00:00 2001 From: HuKeping Date: Fri, 22 Apr 2016 17:29:30 -0400 Subject: [PATCH] Rework function getContainers - Use canonical way to check if a map contains a key. - Use "ci" to keep consistence since it is for "containerInfo". Signed-off-by: Hu Keping --- supervisor/get_containers.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/supervisor/get_containers.go b/supervisor/get_containers.go index 3e24783..23f49c7 100644 --- a/supervisor/get_containers.go +++ b/supervisor/get_containers.go @@ -9,16 +9,20 @@ type GetContainersTask struct { } func (s *Supervisor) getContainers(t *GetContainersTask) error { + if t.ID != "" { - ci := s.containers[t.ID] - if ci == nil { + ci, ok := s.containers[t.ID] + if !ok { return ErrContainerNotFound } t.Containers = append(t.Containers, ci.container) + return nil } - for _, i := range s.containers { - t.Containers = append(t.Containers, i.container) + + for _, ci := range s.containers { + t.Containers = append(t.Containers, ci.container) } + return nil }