addressex/go/addresses.go

52 lines
1.2 KiB
Go
Raw Normal View History

package main
import parser "github.com/openvenues/gopostal/parser"
type Address struct {
Country string
State string
City string
Neighborhood string
Road string
HouseNumber string
House string
Unit string
PostalCode string
}
func parseAddress(address string) Address {
components := parser.ParseAddress(address)
return newFromComponents(components)
}
func newFromComponents(components []parser.ParsedComponent) Address {
address := Address{}
for _, component := range components {
switch component.Label {
case "house":
address.House = component.Value
case "house_number":
address.HouseNumber = component.Value
case "road":
address.Road = component.Value
case "unit":
address.Unit = component.Value
case "postcode":
address.PostalCode = component.Value
case "suburb":
address.Neighborhood = component.Value
case "city_district":
address.Neighborhood = component.Value
case "city":
address.City = component.Value
case "state_district":
address.Neighborhood = component.Value
case "state":
address.State = component.Value
case "country":
address.Country = component.Value
}
}
return address
}