-
Notifications
You must be signed in to change notification settings - Fork 37
/
address.go
127 lines (103 loc) · 3.56 KB
/
address.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
package faker
import (
"fmt"
"reflect"
)
type FakeAddress interface {
City() string // => "North Dessie"
StreetName() string // => "Buckridge Lakes"
StreetAddress() string // => "586 Sylvester Turnpike"
SecondaryAddress() string // => "Apt. 411"
BuildingNumber() string // => "754"
Postcode() string // => "31340"
PostcodeByState(state string) string // => "46511"
ZipCode() string // ZipCode is an alias for Postcode.
ZipCodeByState(state string) string // ZipCodeByState is an alias for PostcodeByState.
TimeZone() string // => "Asia/Taipei"
CityPrefix() string // => "East"
CitySuffix() string // => "town"
StreetSuffix() string // => "Square"
State() string // => "Maryland"
StateAbbr() string // => "IL"
Country() string // => "Uruguay"
CountryCode() string // => "JP"
Latitude() float32 // => -38.811367
Longitude() float32 // => 89.2171
String() string // => "6071 Heaney Island Suite 553, Ebbaville Texas 37307"
}
type fakeAddress struct{}
func Address() FakeAddress {
return fakeAddress{}
}
func (a fakeAddress) City() string {
return Fetch("address.city")
}
func (a fakeAddress) StreetName() string {
return Fetch("address.street_name")
}
func (a fakeAddress) StreetAddress() string {
return Numerify(Fetch("address.street_address"))
}
func (a fakeAddress) SecondaryAddress() string {
return Numerify(Fetch("address.secondary_address"))
}
func (a fakeAddress) BuildingNumber() string {
return NumerifyAndLetterify(Fetch("address.building_number"))
}
func (a fakeAddress) Postcode() string {
return NumerifyAndLetterify(Fetch("address.postcode"))
}
func (a fakeAddress) PostcodeByState(state string) string {
// postcode_by_state can be either a map[string] or a slice (as in default En locale)
switch pbs := valueAt("address.postcode_by_state").(type) {
case map[string]interface{}:
_, ok := pbs[state]
if ok {
return NumerifyAndLetterify(Fetch("address.postcode_by_state." + state))
}
panic(fmt.Sprintf("invalid state: %v", state))
case []string:
return NumerifyAndLetterify(Fetch("address.postcode_by_state"))
default:
panic(fmt.Sprintf("invalid postcode_by_state value type: %v", reflect.TypeOf(pbs)))
}
}
func (a fakeAddress) ZipCode() string {
return a.Postcode()
}
func (a fakeAddress) ZipCodeByState(state string) string {
return a.PostcodeByState(state)
}
func (a fakeAddress) TimeZone() string {
return Fetch("address.time_zone")
}
func (a fakeAddress) CityPrefix() string {
return Fetch("address.city_prefix")
}
func (a fakeAddress) CitySuffix() string {
return Fetch("address.city_suffix")
}
func (a fakeAddress) StreetSuffix() string {
return Fetch("address.street_suffix")
}
func (a fakeAddress) State() string {
return Fetch("address.state")
}
func (a fakeAddress) StateAbbr() string {
return Fetch("address.state_abbr")
}
func (a fakeAddress) Country() string {
return Fetch("address.country")
}
func (a fakeAddress) CountryCode() string {
return Fetch("address.country_code")
}
func (a fakeAddress) Latitude() float32 {
return (localRand.Float32() * 180.0) - 90.0
}
func (a fakeAddress) Longitude() float32 {
return (localRand.Float32() * 360.0) - 180.0
}
func (a fakeAddress) String() string {
return fmt.Sprintf("%v %v, %v %v %v", a.StreetAddress(), a.SecondaryAddress(), a.City(), a.State(), a.Postcode())
}