-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
component.go
81 lines (70 loc) · 2.54 KB
/
component.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package abode
import "googlemaps.github.io/maps"
// Define the different address component types.
const (
AddressComponentTypeSubPremise = "subpremise"
AddressComponentTypePremise = "premise"
AddressComponentTypeStreetNumber = "street_number"
AddressComponentTypeRoute = "route"
AddressComponentTypeStreetAddress = "street_address"
AddressComponentTypeSubLocality = "sublocality"
AddressComponentTypeLocality = "locality"
AddressComponentTypeAdminAreaLevel1 = "administrative_area_level_1"
AddressComponentTypeAdminAreaLevel2 = "administrative_area_level_2"
AddressComponentTypeAdminAreaLevel3 = "administrative_area_level_3"
AddressComponentTypeAdminAreaLevel4 = "administrative_area_level_4"
AddressComponentTypeAdminAreaLevel5 = "administrative_area_level_5"
AddressComponentTypeCountry = "country"
AddressComponentTypePostalCode = "postal_code"
)
// Defines the address components that make up Address.AddressLine1.
var addressLine1Composition = []string{
AddressComponentTypeSubPremise,
AddressComponentTypePremise,
AddressComponentTypeStreetNumber,
AddressComponentTypeRoute,
AddressComponentTypeStreetAddress,
}
// Defines the address components that make up Address.AddressLine2.
var addressLine2Composition = []string{
AddressComponentTypeSubLocality,
}
// Defines the address components that make up Address.AddressCity.
var addressCityComposition = []string{
AddressComponentTypeLocality,
}
// Defines the address components that make up Address.AddressState.
var addressStateComposition = []string{
AddressComponentTypeAdminAreaLevel1,
}
// Defines the address components that make up Address.Country.
var addressCountryComposition = []string{
AddressComponentTypeCountry,
}
// Defines the address components that make up Address.CountryCode.
var addressCountryCodeComposition = []string{
AddressComponentTypeCountry,
}
// Defines the address components that make up Address.Zip.
var addressPostalCodeComposition = []string{
AddressComponentTypePostalCode,
}
// getComponentByType will return the given componentType from a slice of
// maps.AddressComponent's.
func getComponentByType(components []maps.AddressComponent, componentType string) *maps.AddressComponent {
for k, component := range components {
if isComponentType(component.Types, componentType) {
return &components[k]
}
}
return nil
}
// isComponentType will check to see if e is contained within s.
func isComponentType(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}