Skip to content

Commit eaa0576

Browse files
authored
CLEANUP: environment-check: dependent executables error logic refactored (#55)
Since only one error is captured, there is no need for `make([]error, 2)` and index logic. Instead, last error is captured and returned. Additionally, `sync.WaitGroup` exists, but there was no goroutines spawned. So, added `go` keyword to spawn goroutines.
1 parent eaf5442 commit eaa0576

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

haproxy/haproxy_cmd/run.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,31 +118,25 @@ func execAndCapture(path string, re *regexp.Regexp) (string, error) {
118118

119119
// CheckEnvironment Verifies that all dependencies are correct
120120
func CheckEnvironment(dataplaneapiBin, haproxyBin string) error {
121-
errors := make([]error, 2)
121+
var err error
122122
wg := &sync.WaitGroup{}
123123
wg.Add(2)
124-
ensureVersion := func(path, rx, version string, idx int) {
124+
ensureVersion := func(path, rx, version string) {
125+
defer wg.Done()
125126
r := regexp.MustCompile(rx)
126127
v, e := execAndCapture(path, r)
127128
if e != nil {
128-
errors[idx] = e
129+
err = e
129130
} else if strings.Compare(v, "1.2") < 0 {
130-
errors[idx] = fmt.Errorf("%s version must be > 1.2,, but is: %s", path, v)
131+
err = fmt.Errorf("%s version must be > 1.2, but is: %s", path, v)
131132
}
132-
wg.Done()
133133
}
134-
func() {
135-
ensureVersion(haproxyBin, "^HA-Proxy version ([0-9]\\.[0-9]\\.[0-9])", "2.0", 0)
136-
}()
137-
func() {
138-
ensureVersion(dataplaneapiBin, "^HAProxy Data Plane API v([0-9]\\.[0-9]\\.[0-9])", "1.2", 0)
139-
}()
134+
go ensureVersion(haproxyBin, "^HA-Proxy version ([0-9]\\.[0-9]\\.[0-9])", "2.0")
135+
go ensureVersion(dataplaneapiBin, "^HAProxy Data Plane API v([0-9]\\.[0-9]\\.[0-9])", "1.2")
140136

141137
wg.Wait()
142-
for _, err := range errors {
143-
if err != nil {
144-
return err
145-
}
138+
if err != nil {
139+
return err
146140
}
147141
return nil
148142
}

0 commit comments

Comments
 (0)