diff options
| author | Mark Johnston <markjdb@gmail.com> | 2019-03-08 12:45:26 -0500 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2019-03-12 14:30:21 +0100 |
| commit | b4e5a74e4c5d3d833f1fa0f57c7b0a9df8f70f18 (patch) | |
| tree | 92d57bb596e0b3d433263a04f0a3644d11401684 | |
| parent | b489e4987d1c181b1e4d16a8bbc32b97a90b9d8d (diff) | |
pkg/build: reduce cyclomatic complexity of getBuilder()
| -rw-r--r-- | pkg/build/build.go | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/pkg/build/build.go b/pkg/build/build.go index f8a20aabe..620ac5e07 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -63,22 +63,30 @@ type builder interface { } func getBuilder(targetOS, targetArch, vmType string) (builder, error) { - switch { - case targetOS == "linux" && targetArch == "amd64" && vmType == "gvisor": - return gvisor{}, nil - case targetOS == "linux" && targetArch == "amd64" && (vmType == "qemu" || vmType == "gce"): - return linux{}, nil - case targetOS == "fuchsia" && (targetArch == "amd64" || targetArch == "arm64") && vmType == "qemu": - return fuchsia{}, nil - case targetOS == "akaros" && targetArch == "amd64" && vmType == "qemu": - return akaros{}, nil - case targetOS == "openbsd" && targetArch == "amd64" && (vmType == "gce" || vmType == "vmm"): - return openbsd{}, nil - case targetOS == "netbsd" && targetArch == "amd64" && (vmType == "qemu" || vmType == "gce"): - return netbsd{}, nil - default: - return nil, fmt.Errorf("unsupported image type %v/%v/%v", targetOS, targetArch, vmType) + var supported = []struct { + OS string + arch string + vms []string + b builder + }{ + {"linux", "amd64", []string{"gvisor"}, gvisor{}}, + {"linux", "amd64", []string{"gce", "qemu"}, linux{}}, + {"fuchsia", "amd64", []string{"gce"}, fuchsia{}}, + {"fuchsia", "arm64", []string{"gce"}, fuchsia{}}, + {"akaros", "amd64", []string{"qemu"}, akaros{}}, + {"openbsd", "amd64", []string{"gce", "vmm"}, openbsd{}}, + {"netbsd", "amd64", []string{"gce", "qemu"}, netbsd{}}, } + for _, s := range supported { + if targetOS == s.OS && targetArch == s.arch { + for _, vm := range s.vms { + if vmType == vm { + return s.b, nil + } + } + } + } + return nil, fmt.Errorf("unsupported image type %v/%v/%v", targetOS, targetArch, vmType) } func CompilerIdentity(compiler string) (string, error) { |
