-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpeople.go
69 lines (55 loc) · 1.43 KB
/
people.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
package datagen
import (
"fmt"
)
type PeopleObject struct {
o *i18nPeople
}
func People(local ...string) *PeopleObject {
return &PeopleObject{
o: GetLocale(local...).People,
}
}
func (p *PeopleObject) Name() string {
return p.o.Name.RandomString()
}
func (p *PeopleObject) FirstName() string {
return p.o.Name.RandomFirstName()
}
func (p *PeopleObject) LastName() string {
return p.o.Name.RandomLastName()
}
func (p *PeopleObject) Gender() string {
return pick(p.o.Gender)
}
// Phone 生成电话号码
// 现在基本都是手机了各国基本也都是手机和座机号码基本规则一致
func (p *PeopleObject) Phone() string {
return NumberPattern(p.o.Phone)
}
// IDCard 公民唯一号码
// 中国:身份证号
// 美国:社会统一保险号
func (p *PeopleObject) IDCard() string {
return NumberPattern(p.o.IDCard)
}
type i18nPeople struct {
Name i18nName `json:"name"`
Phone string `json:"phone"`
IDCard string `json:"idNumber"`
Gender []string `json:"gender"`
}
type i18nName struct {
First []string `json:"first"`
Last []string `json:"last"`
Split string `json:"split"`
}
func (n *i18nName) RandomFirstName() string {
return pick(n.First)
}
func (n *i18nName) RandomLastName() string {
return pick(n.Last)
}
func (n *i18nName) RandomString() string {
return fmt.Sprintf("%s%s%s", n.RandomFirstName(), n.Split, n.RandomLastName())
}