mirror of
https://github.com/chubin/wttr.in
synced 2025-01-26 02:34:59 +00:00
Add NominatimLocation
This commit is contained in:
parent
45900bc565
commit
2e67874e04
3 changed files with 23 additions and 10 deletions
|
@ -33,12 +33,12 @@ func (l *Address) String() string {
|
|||
if l.Latitude == -1000 {
|
||||
return fmt.Sprintf(
|
||||
"%s;%s;%s;%s",
|
||||
l.CountryCode, l.CountryCode, l.Region, l.City)
|
||||
l.CountryCode, l.Country, l.Region, l.City)
|
||||
}
|
||||
|
||||
return fmt.Sprintf(
|
||||
"%s;%s;%s;%s;%v;%v",
|
||||
l.CountryCode, l.CountryCode, l.Region, l.City, l.Latitude, l.Longitude)
|
||||
l.CountryCode, l.Country, l.Region, l.City, l.Latitude, l.Longitude)
|
||||
}
|
||||
|
||||
// Cache provides access to the IP Geodata cache.
|
||||
|
|
|
@ -6,12 +6,11 @@ import (
|
|||
)
|
||||
|
||||
type Location struct {
|
||||
Name string `db:"name,key"`
|
||||
Lat string `db:"lat"`
|
||||
Lon string `db:"lon"`
|
||||
Timezone string `db:"timezone"`
|
||||
//nolint:tagliatelle
|
||||
Fullname string `db:"displayName" json:"display_name"`
|
||||
Name string `db:"name,key" json:"name"`
|
||||
Lat string `db:"lat" json:"latitude"`
|
||||
Lon string `db:"lon" json:"longitude"`
|
||||
Timezone string `db:"timezone" json:"timezone"`
|
||||
Fullname string `db:"displayName" json:"address"`
|
||||
}
|
||||
|
||||
// String returns string representation of location.
|
||||
|
|
|
@ -17,6 +17,14 @@ type Nominatim struct {
|
|||
token string
|
||||
}
|
||||
|
||||
type NominatimLocation struct {
|
||||
Name string `db:"name,key"`
|
||||
Lat string `db:"lat"`
|
||||
Lon string `db:"lon"`
|
||||
//nolint:tagliatelle
|
||||
Fullname string `db:"displayName" json:"display_name"`
|
||||
}
|
||||
|
||||
func NewNominatim(name, url, token string) *Nominatim {
|
||||
return &Nominatim{
|
||||
name: name,
|
||||
|
@ -27,7 +35,7 @@ func NewNominatim(name, url, token string) *Nominatim {
|
|||
|
||||
func (n *Nominatim) Query(location string) (*Location, error) {
|
||||
var (
|
||||
result []Location
|
||||
result []NominatimLocation
|
||||
|
||||
errResponse struct {
|
||||
Error string
|
||||
|
@ -65,5 +73,11 @@ func (n *Nominatim) Query(location string) (*Location, error) {
|
|||
return nil, fmt.Errorf("%w: %s: invalid response", types.ErrUpstream, n.name)
|
||||
}
|
||||
|
||||
return &result[0], nil
|
||||
nl := &result[0]
|
||||
|
||||
return &Location{
|
||||
Lat: nl.Lat,
|
||||
Lon: nl.Lon,
|
||||
Fullname: nl.Fullname,
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue