From 4ba1d2dfb423ca6a03b58eca373346910627da5c Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Wed, 26 Jul 2023 12:17:18 +0100 Subject: [PATCH] Skip table lines properly. --- main.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index cafbd2c..7e9f85f 100644 --- a/main.go +++ b/main.go @@ -87,11 +87,7 @@ func getConfig(ApiUrl string) (FrontendConfig, error) { return config, nil } -func getInstanceDetails(line string, latest string) (Instance, error) { - split := strings.Split(line, "|") - if len(split) < 5 { - return Instance{}, errors.New(fmt.Sprintf("Invalid line: %s", line)) - } +func getInstanceDetails(split []string, latest string) (Instance, error) { ApiUrl := strings.TrimSpace(split[1]) wg := sync.WaitGroup{} @@ -245,22 +241,31 @@ func monitorInstances() { instances := []Instance{} wg := sync.WaitGroup{} - for index, line := range lines { - // skip first two and last line - if index < 2 || index == len(lines)-1 { + + skipped := 0 + for _, line := range lines { + split := strings.Split(line, "|") + + if len(split) < 5 { + continue + } + + // skip first two table lines + if skipped < 2 { + skipped++ continue } wg.Add(1) - go func(line string) { + go func(split []string) { defer wg.Done() - instance, err := getInstanceDetails(line, latest) + instance, err := getInstanceDetails(split, latest) if err == nil { instances = append(instances, instance) } else { log.Print(err) } - }(line) + }(split) } wg.Wait()