Documentation
¶
Overview ¶
Package libaddress is a library that validates address using data generated from Google's Address Data Service
Code generated by libaddress. DO NOT EDIT.
Index ¶
- Variables
- func ListFormatFunc(es []error) string
- func Validate(address Address) error
- func WithAdministrativeArea(administrativeArea string) func(*Address)
- func WithCountry(cc string) func(*Address)
- func WithDependentLocality(dependentLocality string) func(*Address)
- func WithLocality(locality string) func(*Address)
- func WithName(name string) func(*Address)
- func WithOrganization(organization string) func(*Address)
- func WithPostCode(postCode string) func(*Address)
- func WithSortingCode(sortingCode string) func(*Address)
- func WithStreetAddress(streetAddress []string) func(*Address)
- type Address
- type AdministrativeAreaData
- type AdministrativeAreaSlice
- type CountryData
- type CountryList
- type CountryListItem
- type DependentLocalityData
- type DependentLocalityDataSlice
- type DisplayField
- type DisplayFieldName
- type ErrMissingRequiredFields
- type ErrUnsupportedFields
- type ExternalCountry
- type Field
- type FieldName
- type LocalityData
- type LocalitySlice
- type PostCodeRegexData
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidCountryCode indicates that the country code // used to create an address is invalid ErrInvalidCountryCode = errors.New("invalid:Country") // ErrInvalidDependentLocality indicates that the dependent // locality is invalid. This is usually due to the country // having a pre-determined list of dependent localities and // the value does not match any of the keys in the list of // dependent localities. ErrInvalidDependentLocality = errors.New("invalid:DependentLocality") // ErrInvalidLocality indicates that the locality is invalid. // This is usually due to the country having a pre-determined // list of localities and the value does not match any of the // keys in the list of localities ErrInvalidLocality = errors.New("invalid:Locality") // ErrInvalidAdministrativeArea indicates that the administrative // area is invalid. This is usually due to the country having a // pre-determined list of administrative areas and the value // does not match any of the keys in the list of administrative // areas. ErrInvalidAdministrativeArea = errors.New("invalid:AdministrativeArea") // ErrInvalidPostCode indicates that the post code did not validate // using the regular expression of the country ErrInvalidPostCode = errors.New("invalid:PostCode") )
Functions ¶
func ListFormatFunc ¶
func Validate ¶
Validate checks an address to determine if it is valid. To create a valid address, the `address.NewValid()` function can do it in one call.
func WithAdministrativeArea ¶
WithAdministrativeArea sets the administrative area (commonly known as the state) of an address. If the country of the address has a list of administrative areas, then the key of the administrative area should be used, otherwise, the validation will fail.
func WithCountry ¶
WithCountry sets the country code of an address. The country code must be an ISO 3166-1 country code.
func WithDependentLocality ¶
WithDependentLocality sets the dependent locality (commonly know as the suburb) of an address. If the country of the address has a list of dependent localities, then the key of the dependent locality should be used, otherwise the validation will fail.
func WithLocality ¶
WithLocality sets the locality (commonly known as the city) of an address. If the country of the address has a list of localities, then the keys of the locality should be used, otherwise validation will fail.
func WithOrganization ¶
WithOrganization sets teh addressee's organization of an address
func WithPostCode ¶
WithPostCode sets the post code of an address.
func WithSortingCode ¶
WithSortingCode sets the sorting code of an address.
func WithStreetAddress ¶
WithStreetAddress sets the street address of an address. The street address is a slice of strings, with each element representing an address line.
Types ¶
type Address ¶
type Address struct { Country string Name string Organization string StreetAddress []string DependentLocality string Locality string AdministrativeArea string PostCode string SortingCode string }
Address represents a valid address made up of its child components
func New ¶
New creates a new unvalidated address. The validity of the address should be checked using the validator.
func NewValid ¶
NewValid creates a new Address. If the address is invalid, an error is returned. In the case where an error is returned, the error is a hashicorp/go-multierror (https://github.com/hashicorp/go-multierror). You can use a type switch to get a list of validation errors for the address.
type AdministrativeAreaData ¶
type AdministrativeAreaData struct { ID string Name string Localities LocalitySlice }
AdministrativeAreaData contains the name and ID of an administrative area. The ID must be passed to WithAdministrativeArea() when creating an address. The name is useful for displaying to the end user.
type AdministrativeAreaSlice ¶
type AdministrativeAreaSlice []AdministrativeAreaData
type CountryData ¶
type CountryData struct { Format string `json:"format"` LatinizedFormat string `json:"latinized_format"` Required []Field `json:"required"` Allowed []Field `json:"allowed"` DefaultLanguage string `json:"default_language"` AdministrativeAreaNameType FieldName `json:"administrative_area_name_type"` LocalityNameType FieldName `json:"locality_name_type"` DependentLocalityNameType FieldName `json:"dependent_locality_name_type"` PostCodeNameType FieldName `json:"post_code_name_type"` PostCodeRegex PostCodeRegexData `json:"post_code_regex"` AdministrativeAreas map[string]AdministrativeAreaSlice `json:"administrative_areas"` }
CountryData contains the address data for a country. The AdministrativeAreas field contains a list of nested subdivisions (administrative areas, localities and dependent localities) grouped by their translated languages. They are also sorted according to the sort order of the languages they are in.
func GetCountry ¶
func GetCountry(cc string) CountryData
Get country returns address information for a given country.
type CountryList ¶
type CountryList []CountryListItem
CountryList contains a list of countries that can be used to create addresses.
func ListCountries ¶
func ListCountries(l string) CountryList
ListCountries returns a list of countries that can be used to create addresses. Language must be a valid ISO 639-1 language code such as jp, zh etc. If the language does not have any translations or is invalid then english is used as the fallback. The returned list of countries is sorted according to the chosen language.
func (CountryList) Bytes ¶
func (c CountryList) Bytes(i int) []byte
Bytes returns a country name in bytes. This is used for sorting the countries and would not be generally used in client code.
func (CountryList) Len ¶
func (c CountryList) Len() int
Len returns the number of countries in the list. This is used for sorting the countries and would not be generally used in client code.
func (CountryList) Swap ¶
func (c CountryList) Swap(i, j int)
Swap swaps 2 countries in the list. This is used for sorting the countries and would not be generally used in client code.
type CountryListItem ¶
CountryListItem represents a single country containing the ISO 3166-1 code and the name of the country.
type DependentLocalityData ¶
DependentLocalityData contains the name and ID of a dependent locality. The ID must be passed to WithDependentLocalityData() when creating an address. The name is useful for displaying to the end user.
type DependentLocalityDataSlice ¶
type DependentLocalityDataSlice []DependentLocalityData
type DisplayField ¶
type DisplayFieldName ¶
type ErrMissingRequiredFields ¶
type ErrMissingRequiredFields struct { Fields []Field // contains filtered or unexported fields }
ErrMissingRequiredFields indicates that a required address field is missing. The Fields field can be used can be used to get a list of missing field.
func (ErrMissingRequiredFields) Error ¶
func (e ErrMissingRequiredFields) Error() string
type ErrUnsupportedFields ¶
type ErrUnsupportedFields struct { Fields []Field // contains filtered or unexported fields }
ErrUnsupportedFields indicates that an address field is provided, but it is not supported by the address format of the country. The Fields field can be used to get a list of unsupported fields.
func (ErrUnsupportedFields) Error ¶
func (e ErrUnsupportedFields) Error() string
type ExternalCountry ¶
type ExternalCountry struct { Required []*DisplayField `json:"required"` Allowed []*DisplayField `json:"allowed"` Language string `json:"language"` AdministrativeAreaNameType *DisplayFieldName `json:"administrative_area_name_type"` LocalityNameType *DisplayFieldName `json:"locality_name_type"` DependentLocalityNameType *DisplayFieldName `json:"dependent_locality_name_type"` PostCodeNameType *DisplayFieldName `json:"post_code_name_type"` AdministrativeAreas map[string]AdministrativeAreaSlice `json:"administrative_areas"` }
func Externalize ¶
func Externalize(c country) ExternalCountry
func GetExternalCountry ¶
func GetExternalCountry(cc string) ExternalCountry
Get external country returns readadble address information for a given country.
type Field ¶
type Field int
Field is an address field type.
func (Field) Key ¶
Key returns the corresponding one-letter abbreviation used by Google to refer to address fields. This is useful for parsing the address format for a country. See https://github.com/googlei18n/libaddressinput/wiki/AddressValidationMetadata for more information
type FieldName ¶
type FieldName int
FieldName is the name to be used when referring to a field. For example, in India the postal code is called PIN Code instead of PostalCode. The field name allows you to display the appropriate form labels to the user.
type LocalityData ¶
type LocalityData struct { ID string Name string DependentLocalities DependentLocalityDataSlice }
LocalityData contains the name and ID of a locality. The ID must be passed to WithLocalityData() when creating an address. The name is useful for displaying to the end user.
type LocalitySlice ¶
type LocalitySlice []LocalityData
type PostCodeRegexData ¶
type PostCodeRegexData struct { Regex string SubdivisionRegex map[string]PostCodeRegexData }
PostCodeRegexData contains regular expressions for validating post codes for a given country. If the country has subdivisions (administrative areas, localities and dependent localities), the SubdivisionRegex field may contain further regular expressions to Validate the post code.