This repository has been archived by the owner on Sep 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperson.go
70 lines (64 loc) · 1.77 KB
/
person.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
package faker
// FirstName returns random first name
func (f *Faker) FirstName() string {
return FirstName(
WithRand(f.cfg.rand),
WithFirstNames(f.cfg.firstNames...),
)
}
// FirstName returns random first name
//
// faker.FirstName(
// faker.WithRand(rand.New(rand.NewSource(time.Now().Unix()))), // Rand instance
// faker.WithFirstNames("Tom", "Dick", "Harry"), // Slice of first names for RandomElement
// )
//
func FirstName(opts ...Option) string {
cfg := newConfig(opts...)
if len(cfg.firstNames) == 0 {
WithFirstNames("Tom", "Dick", "Harry")(cfg)
}
return RandomElement(cfg.firstNames, opts...)
}
// LastName returns random last name
func (f *Faker) LastName() string {
return LastName(
WithRand(f.cfg.rand),
WithLastNames(f.cfg.lastNames...),
)
}
// LastName returns random last name
//
// faker.LastName(
// faker.WithRand(rand.New(rand.NewSource(time.Now().Unix()))), // Rand instance
// faker.WithLastNames("Bloggs", "Doe", "Schmoe", "Smith"),
// )
//
func LastName(opts ...Option) string {
cfg := newConfig(opts...)
if len(cfg.lastNames) == 0 {
WithLastNames("Bloggs", "Doe", "Schmoe", "Smith")(cfg)
}
return RandomElement(cfg.lastNames, opts...)
}
// Name returns random name
func (f *Faker) Name() string {
return Name(
WithRand(f.cfg.rand),
WithFirstNames(f.cfg.firstNames...),
WithLastNames(f.cfg.lastNames...),
)
}
// Name returns random name
//
// faker.Name(
// faker.WithRand(rand.New(rand.NewSource(time.Now().Unix()))), // Rand instance
// faker.WithFirstNames("Tom", "Dick", "Harry"),
// faker.WithLastNames("Bloggs", "Doe", "Schmoe", "Smith"),
// )
//
func Name(opts ...Option) string {
firstName := FirstName(opts...)
lastName := LastName(opts...)
return firstName + " " + lastName
}