gokedex/internal/pokeapi/location_list.go
2025-06-05 12:10:26 -06:00

33 lines
641 B
Go

package pokeapi
import (
"encoding/json"
"net/http"
)
func (c *Client) ListLocations(pageUrl *string) (RespShallowLocations, error) {
url := baseUrl + "/location-area"
if pageUrl != nil {
url = *pageUrl
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return RespShallowLocations{}, err
}
resp, err := c.httpClient.Do(req)
if err != nil {
return RespShallowLocations{}, err
}
defer resp.Body.Close()
var locationsResp RespShallowLocations
decoder := json.NewDecoder(resp.Body)
if err = decoder.Decode(&locationsResp); err != nil {
return RespShallowLocations{}, err
}
return locationsResp, nil
}