mirror of
https://github.com/TeamPiped/instances-api.git
synced 2024-08-14 23:57:19 +00:00
Skip table lines properly.
This commit is contained in:
parent
c369f2b7bc
commit
4ba1d2dfb4
1 changed files with 16 additions and 11 deletions
27
main.go
27
main.go
|
@ -87,11 +87,7 @@ func getConfig(ApiUrl string) (FrontendConfig, error) {
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getInstanceDetails(line string, latest string) (Instance, error) {
|
func getInstanceDetails(split []string, latest string) (Instance, error) {
|
||||||
split := strings.Split(line, "|")
|
|
||||||
if len(split) < 5 {
|
|
||||||
return Instance{}, errors.New(fmt.Sprintf("Invalid line: %s", line))
|
|
||||||
}
|
|
||||||
ApiUrl := strings.TrimSpace(split[1])
|
ApiUrl := strings.TrimSpace(split[1])
|
||||||
|
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
|
@ -245,22 +241,31 @@ func monitorInstances() {
|
||||||
instances := []Instance{}
|
instances := []Instance{}
|
||||||
|
|
||||||
wg := sync.WaitGroup{}
|
wg := sync.WaitGroup{}
|
||||||
for index, line := range lines {
|
|
||||||
// skip first two and last line
|
skipped := 0
|
||||||
if index < 2 || index == len(lines)-1 {
|
for _, line := range lines {
|
||||||
|
split := strings.Split(line, "|")
|
||||||
|
|
||||||
|
if len(split) < 5 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// skip first two table lines
|
||||||
|
if skipped < 2 {
|
||||||
|
skipped++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(line string) {
|
go func(split []string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
instance, err := getInstanceDetails(line, latest)
|
instance, err := getInstanceDetails(split, latest)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
instances = append(instances, instance)
|
instances = append(instances, instance)
|
||||||
} else {
|
} else {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
}
|
}
|
||||||
}(line)
|
}(split)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue