feat(go): implement server to parse address

This commit is contained in:
Joao P Dubas
2024-01-29 12:31:04 +00:00
parent d355f46856
commit 1b96d3aebc
5 changed files with 214 additions and 5 deletions

51
go/addresses.go Normal file
View File

@@ -0,0 +1,51 @@
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
}