-
Notifications
You must be signed in to change notification settings - Fork 3
/
const.go
181 lines (153 loc) · 4.25 KB
/
const.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Copyright (c) 2020 Bojan Zivanovic and contributors
// SPDX-License-Identifier: MIT
package address
import "fmt"
// Field represents an address field.
type Field string
const (
FieldLine1 Field = "1"
FieldLine2 Field = "2"
FieldLine3 Field = "3"
FieldSublocality Field = "S"
FieldLocality Field = "L"
FieldRegion Field = "R"
FieldPostalCode Field = "P"
)
// SublocalityType represents the sublocality type.
type SublocalityType uint8
const (
SublocalityTypeSuburb SublocalityType = iota
SublocalityTypeDistrict
SublocalityTypeNeighborhood
SublocalityTypeVillageTownship
SublocalityTypeTownland
)
var sublocalityTypeNames = [...]string{"suburb", "district", "neighborhood", "village_township", "townland"}
// String returns the string representation of s.
func (s SublocalityType) String() string {
if int(s) >= len(sublocalityTypeNames) {
return ""
}
return sublocalityTypeNames[s]
}
// MarshalText implements the encoding.TextMarshaler interface.
func (s SublocalityType) MarshalText() ([]byte, error) {
return []byte(s.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface.
func (s *SublocalityType) UnmarshalText(b []byte) error {
aux := string(b)
for i, name := range sublocalityTypeNames {
if name == aux {
*s = SublocalityType(i)
return nil
}
}
return fmt.Errorf("invalid sublocality type %q", aux)
}
// LocalityType represents the locality type.
type LocalityType uint8
const (
LocalityTypeCity LocalityType = iota
LocalityTypeDistrict
LocalityTypePostTown
LocalityTypeSuburb
LocalityTypeTownCity
)
var localityTypeNames = [...]string{"city", "district", "post_town", "suburb"}
// String returns the string representation of l.
func (l LocalityType) String() string {
if int(l) >= len(localityTypeNames) {
return ""
}
return localityTypeNames[l]
}
// MarshalText implements the encoding.TextMarshaler interface.
func (l LocalityType) MarshalText() ([]byte, error) {
return []byte(l.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface.
func (l *LocalityType) UnmarshalText(b []byte) error {
aux := string(b)
for i, name := range localityTypeNames {
if name == aux {
*l = LocalityType(i)
return nil
}
}
return fmt.Errorf("invalid locality type %q", aux)
}
// RegionType represents the region type.
type RegionType uint8
const (
RegionTypeProvince RegionType = iota
RegionTypeArea
RegionTypeCanton
RegionTypeCounty
RegionTypeDepartment
RegionTypeDistrict
RegionTypeDoSi
RegionTypeEmirate
RegionTypeIsland
RegionTypeParish
RegionTypePrefecture
RegionTypeRegion
RegionTypeState
)
var regionTypeNames = [...]string{
"province", "area", "canton", "department", "distict", "do_si",
"emirate", "island", "parish", "prefecture", "region", "state",
}
// String returns the string representation of r.
func (r RegionType) String() string {
if int(r) >= len(regionTypeNames) {
return ""
}
return regionTypeNames[r]
}
// MarshalText implements the encoding.TextMarshaler interface.
func (r RegionType) MarshalText() ([]byte, error) {
return []byte(r.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface.
func (r *RegionType) UnmarshalText(b []byte) error {
aux := string(b)
for i, name := range regionTypeNames {
if name == aux {
*r = RegionType(i)
return nil
}
}
return fmt.Errorf("invalid region type %q", aux)
}
// PostalCodeType represents the postal code type.
type PostalCodeType uint8
const (
PostalCodeTypePostal PostalCodeType = iota
PostalCodeTypeEir
PostalCodeTypePin
PostalCodeTypeZip
)
var postalCodeTypeNames = [...]string{"postal", "eir", "pin", "zip"}
// String returns the string representation of p.
func (p PostalCodeType) String() string {
if int(p) >= len(postalCodeTypeNames) {
return ""
}
return postalCodeTypeNames[p]
}
// MarshalText implements the encoding.TextMarshaler interface.
func (p PostalCodeType) MarshalText() ([]byte, error) {
return []byte(p.String()), nil
}
// UnmarshalText implements the encoding.TextUnmarshaler interface.
func (p *PostalCodeType) UnmarshalText(b []byte) error {
aux := string(b)
for i, name := range postalCodeTypeNames {
if name == aux {
*p = PostalCodeType(i)
return nil
}
}
return fmt.Errorf("invalid postal code type %q", aux)
}