Skip table lines properly.

This commit is contained in:
Kavin 2023-07-26 12:17:18 +01:00
parent c369f2b7bc
commit 4ba1d2dfb4
No known key found for this signature in database
GPG Key ID: 6E4598CA5C92C41F
1 changed files with 16 additions and 11 deletions

27
main.go
View File

@ -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()