/
phone.go
43 lines (34 loc) · 870 Bytes
/
phone.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
package faker
import "reflect"
type Phone struct {
Number string
Format string
}
func (phone *Phone) Numberʹ(params ...interface{}) string {
format := phone.Formatʹ()
types := kindOf(params...)
if len(types) >= 1 && types[0] == reflect.String {
format = params[0].(string)
}
phone.Number = replaceSymbolWithNumber(format, '#')
phone.Format = format
return phone.Number
}
func (phone *Phone) Formatʹ() string {
format := getData("Phone", "PhoneFormat")
phone.Format = sample(format)
return phone.Format
}
// Fake Generate random data for all field
func (phone *Phone) Fake() {
phone.Formatʹ()
phone.Numberʹ()
}
// ToJSON Encode name and its fields to JSON.
func (phone *Phone) ToJSON() (string, error) {
return ToJSON(phone)
}
// ToXML Encode name and its fields to XML.
func (phone *Phone) ToXML() (string, error) {
return ToXML(phone)
}