Skip to content

Commit 4914fca

Browse files
authored
fix: error when new world is first in b.Worlds (#72)
1 parent 252017f commit 4914fca

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/workers.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,20 @@ func (b *Builder) housesWorker(client *resty.Client) error {
7373

7474
})
7575

76+
// Find the index of Antica in b.Worlds[] or fallback to first index
77+
worldsIndex := func() int {
78+
for i, world := range b.Worlds {
79+
if world == "Antica" {
80+
return i
81+
}
82+
}
83+
return 0
84+
}()
85+
7686
for _, town := range b.Towns {
7787
log.Printf("[info] Retrieving data about houses and guildhalls in %s.", town)
7888

79-
ApiUrl := "https://" + TibiaDataAPIhost + "/v4/houses/" + b.Worlds[0] + "/" + url.QueryEscape(town)
89+
ApiUrl := "https://" + TibiaDataAPIhost + "/v4/houses/" + b.Worlds[worldsIndex] + "/" + url.QueryEscape(town)
8090
res, err := client.R().Get(ApiUrl)
8191
if err != nil {
8292
return fmt.Errorf("issue getting %s endpoint. Error: %s", ApiUrl, err)

0 commit comments

Comments
 (0)