-
Notifications
You must be signed in to change notification settings - Fork 53
/
address.go
40 lines (33 loc) · 825 Bytes
/
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
package generator
// Address represent an address
type Address struct {
Address string `json:"address,omitempty" validate:"required"`
Address2 string `json:"address_2,omitempty"`
PostalCode string `json:"postal_code,omitempty"`
City string `json:"city,omitempty"`
Country string `json:"country,omitempty"`
}
// ToString output address as string
// Line break are added for new lines
func (a *Address) ToString() string {
addrString := a.Address
if len(a.Address2) > 0 {
addrString += "\n"
addrString += a.Address2
}
if len(a.PostalCode) > 0 {
addrString += "\n"
addrString += a.PostalCode
} else {
addrString += "\n"
}
if len(a.City) > 0 {
addrString += " "
addrString += a.City
}
if len(a.Country) > 0 {
addrString += "\n"
addrString += a.Country
}
return addrString
}