From 31d12693e873d059afcdfd8b0a9fe14f67c198d1 Mon Sep 17 00:00:00 2001 From: Tobias Lindberg Date: Wed, 16 Oct 2024 13:09:26 +0200 Subject: [PATCH] fix: error when new world is first in b.Worlds --- src/workers.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/workers.go b/src/workers.go index 0e6fb66..93635f0 100644 --- a/src/workers.go +++ b/src/workers.go @@ -73,10 +73,20 @@ func (b *Builder) housesWorker(client *resty.Client) error { }) + // Find the index of Antica in b.Worlds[] or fallback to first index + worldsIndex := func() int { + for i, world := range b.Worlds { + if world == "Antica" { + return i + } + } + return 0 + }() + for _, town := range b.Towns { log.Printf("[info] Retrieving data about houses and guildhalls in %s.", town) - ApiUrl := "https://" + TibiaDataAPIhost + "/v4/houses/" + b.Worlds[0] + "/" + url.QueryEscape(town) + ApiUrl := "https://" + TibiaDataAPIhost + "/v4/houses/" + b.Worlds[worldsIndex] + "/" + url.QueryEscape(town) res, err := client.R().Get(ApiUrl) if err != nil { return fmt.Errorf("issue getting %s endpoint. Error: %s", ApiUrl, err)