-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuserdata.go
68 lines (61 loc) · 2.26 KB
/
userdata.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
package amiando
import "fmt"
type UserDataType string
const (
UserDataString UserDataType = "string" // value is of type String.
UserDataNumber UserDataType = "number" // value is of type Integer.
UserDataDate UserDataType = "date" // value is of type Date.
UserDataGender UserDataType = "gender" // value is of type Integer.
UserDataEmail UserDataType = "email" // value is of type String.
UserDataUrl UserDataType = "url" // value is of type String.
UserDataBirthday UserDataType = "birthday" // value is of type Date.
UserDataAddress UserDataType = "address" // value is an object of type Address.
UserDataPhone UserDataType = "phone" // value is of type String.
UserDataZipCode UserDataType = "zipCode" // value is of type String.
UserDataCountry UserDataType = "country" // value is of type Country. Country codes are defined by the ISO 3166-1-alpha-2 code standard
UserDataBlog UserDataType = "blog" // value is of type String.
UserDataCheckbox UserDataType = "checkbox" // value is of type Bool
UserDataRadiobutton UserDataType = "radio" // value is of type String.
UserDataDropdown UserDataType = "dropdown" // value is of type String.
UserDataTextArea UserDataType = "textarea" // value is of type String.
UserDataProduct UserDataType = "product" // value is of type String.
UserDataPhoto UserDataType = "photo" // value is of type String (URL)
)
type UserData struct {
Title string `json:"title"`
Type UserDataType `json:"type"`
Value interface{} `json:"value"`
}
func (self *UserData) String() string {
return fmt.Sprintf("%v", self.Value)
}
func (self *UserData) Address() *Address {
if self.Type != UserDataAddress {
return nil
}
data := self.Value.(map[string]interface{})
addr := new(Address)
if v, ok := data["street"]; ok {
addr.Street = v.(string)
}
if v, ok := data["street2"]; ok {
addr.Street2 = v.(string)
}
if v, ok := data["city"]; ok {
addr.City = v.(string)
}
if v, ok := data["zipCode"]; ok {
addr.ZipCode = v.(string)
}
if v, ok := data["country"]; ok {
addr.Country = v.(string)
}
return addr
}
type Address struct {
Street string
Street2 string
City string
ZipCode string
Country string
}