forked from brianvoe/gofakeit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
97 lines (82 loc) · 2.03 KB
/
app.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package gofakeit
import (
"fmt"
"math/rand"
)
// AppName will generate a random app name
func AppName() string {
return appName(globalFaker.Rand)
}
// AppName will generate a random app name
func (f *Faker) AppName() string {
return appName(f.Rand)
}
func appName(r *rand.Rand) string {
name := ""
switch number(r, 1, 3) {
case 1:
name = noun(r) + verb(r)
case 2:
name = color(r) + noun(r)
case 3:
name = animal(r) + verb(r)
}
return title(name)
}
// AppVersion will generate a random app version
func AppVersion() string {
return appVersion(globalFaker.Rand)
}
// AppVersion will generate a random app version
func (f *Faker) AppVersion() string {
return appVersion(f.Rand)
}
func appVersion(r *rand.Rand) string {
return fmt.Sprintf("%d.%d.%d", number(r, 1, 5), number(r, 1, 20), number(r, 1, 20))
}
// AppAuthor will generate a random company or person name
func AppAuthor() string {
return appAuthor(globalFaker.Rand)
}
// AppAuthor will generate a random company or person name
func (f *Faker) AppAuthor() string {
return appAuthor(f.Rand)
}
func appAuthor(r *rand.Rand) string {
if boolFunc(r) {
return name(r)
}
return company(r)
}
func addAppLookup() {
AddFuncLookup("appname", Info{
Display: "App Name",
Category: "app",
Description: "Random app name",
Example: "Parkrespond",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return appName(r), nil
},
})
AddFuncLookup("appversion", Info{
Display: "App Version",
Category: "app",
Description: "Random app version",
Example: "1.12.14",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return appVersion(r), nil
},
})
AddFuncLookup("appauthor", Info{
Display: "App Author",
Category: "app",
Description: "Random app author",
Example: "Qado Energy, Inc.",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return appAuthor(r), nil
},
})
}