mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 08:16:39 +00:00
Fixes panic occurring when body is nil (this usually happens when connections is refused) due to lack of nil check by centralizing response.Body.Close() behavior.
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package rest
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/netbirdio/netbird/management/server/http/api"
|
|
)
|
|
|
|
// GeoLocationAPI APIs for Geo-Location, do not use directly
|
|
type GeoLocationAPI struct {
|
|
c *Client
|
|
}
|
|
|
|
// ListCountries list all country codes
|
|
// See more: https://docs.netbird.io/api/resources/geo-locations#list-all-country-codes
|
|
func (a *GeoLocationAPI) ListCountries(ctx context.Context) ([]api.Country, error) {
|
|
resp, err := a.c.newRequest(ctx, "GET", "/api/locations/countries", nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.Body != nil {
|
|
defer resp.Body.Close()
|
|
}
|
|
ret, err := parseResponse[[]api.Country](resp)
|
|
return ret, err
|
|
}
|
|
|
|
// ListCountryCities Get a list of all English city names for a given country code
|
|
// See more: https://docs.netbird.io/api/resources/geo-locations#list-all-city-names-by-country
|
|
func (a *GeoLocationAPI) ListCountryCities(ctx context.Context, countryCode string) ([]api.City, error) {
|
|
resp, err := a.c.newRequest(ctx, "GET", "/api/locations/countries/"+countryCode+"/cities", nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if resp.Body != nil {
|
|
defer resp.Body.Close()
|
|
}
|
|
ret, err := parseResponse[[]api.City](resp)
|
|
return ret, err
|
|
}
|