39 lines
756 B
Go
39 lines
756 B
Go
|
|
package libpostal
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"strings"
|
||
|
|
)
|
||
|
|
|
||
|
|
type Address struct {
|
||
|
|
HouseNumber string
|
||
|
|
Road string
|
||
|
|
City string
|
||
|
|
State string
|
||
|
|
PostCode string
|
||
|
|
}
|
||
|
|
|
||
|
|
func (a *Address) Invalid() error {
|
||
|
|
var missingFields []string
|
||
|
|
if len(a.HouseNumber) == 0 {
|
||
|
|
missingFields = append(missingFields, "HouseNumber")
|
||
|
|
}
|
||
|
|
if len(a.Road) == 0 {
|
||
|
|
missingFields = append(missingFields, "Road")
|
||
|
|
}
|
||
|
|
if len(a.City) == 0 {
|
||
|
|
missingFields = append(missingFields, "City")
|
||
|
|
}
|
||
|
|
if len(a.State) == 0 {
|
||
|
|
missingFields = append(missingFields, "State")
|
||
|
|
}
|
||
|
|
if len(a.PostCode) == 0 {
|
||
|
|
missingFields = append(missingFields, "PostCode")
|
||
|
|
}
|
||
|
|
|
||
|
|
if len(missingFields) > 0 {
|
||
|
|
return fmt.Errorf("missing fields: %s", strings.Join(missingFields, ", "))
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|