optimize then function in kind visitor

Signed-off-by: yuexiao-wang <wang.yuexiao@zte.com.cn>
This commit is contained in:
yuexiao-wang 2017-09-15 17:21:22 +08:00
parent 5d995e3f7b
commit 0bfd6104a1

View File

@ -39,35 +39,25 @@ type GroupKindElement schema.GroupKind
// Accept calls the Visit method on visitor that corresponds to elem's Kind
func (elem GroupKindElement) Accept(visitor KindVisitor) error {
if elem.GroupMatch("apps", "extensions") && elem.Kind == "DaemonSet" {
switch {
case elem.GroupMatch("apps", "extensions") && elem.Kind == "DaemonSet":
visitor.VisitDaemonSet(elem)
return nil
}
if elem.GroupMatch("apps", "extensions") && elem.Kind == "Deployment" {
case elem.GroupMatch("apps", "extensions") && elem.Kind == "Deployment":
visitor.VisitDeployment(elem)
return nil
}
if elem.GroupMatch("batch") && elem.Kind == "Job" {
case elem.GroupMatch("batch") && elem.Kind == "Job":
visitor.VisitJob(elem)
return nil
}
if elem.GroupMatch("", "core") && elem.Kind == "Pod" {
case elem.GroupMatch("", "core") && elem.Kind == "Pod":
visitor.VisitPod(elem)
return nil
}
if elem.GroupMatch("extensions") && elem.Kind == "ReplicaSet" {
case elem.GroupMatch("extensions") && elem.Kind == "ReplicaSet":
visitor.VisitReplicaSet(elem)
return nil
}
if elem.GroupMatch("", "core") && elem.Kind == "ReplicationController" {
case elem.GroupMatch("", "core") && elem.Kind == "ReplicationController":
visitor.VisitReplicationController(elem)
return nil
}
if elem.GroupMatch("apps") && elem.Kind == "StatefulSet" {
case elem.GroupMatch("apps") && elem.Kind == "StatefulSet":
visitor.VisitStatefulSet(elem)
return nil
default:
return fmt.Errorf("no visitor method exists for %v", elem)
}
return fmt.Errorf("no visitor method exists for %v", elem)
return nil
}
// GroupMatch returns true if and only if elem's group matches one