forked from brianvoe/gofakeit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
car.go
141 lines (115 loc) · 4.35 KB
/
car.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package gofakeit
import "math/rand"
// CarInfo is a struct dataset of all car information
type CarInfo struct {
Type string `json:"type" xml:"type"`
Fuel string `json:"fuel" xml:"fuel"`
Transmission string `json:"transmission" xml:"transmission"`
Brand string `json:"brand" xml:"brand"`
Model string `json:"model" xml:"model"`
Year int `json:"year" xml:"year"`
}
// Car will generate a struct with car information
func Car() *CarInfo { return car(globalFaker.Rand) }
// Car will generate a struct with car information
func (f *Faker) Car() *CarInfo { return car(f.Rand) }
func car(r *rand.Rand) *CarInfo {
return &CarInfo{
Type: carType(r),
Fuel: carFuelType(r),
Transmission: carTransmissionType(r),
Brand: carMaker(r),
Model: carModel(r),
Year: year(r),
}
}
// CarType will generate a random car type string
func CarType() string { return carType(globalFaker.Rand) }
// CarType will generate a random car type string
func (f *Faker) CarType() string { return carType(f.Rand) }
func carType(r *rand.Rand) string { return getRandValue(r, []string{"car", "type"}) }
// CarFuelType will return a random fuel type
func CarFuelType() string { return carFuelType(globalFaker.Rand) }
// CarFuelType will return a random fuel type
func (f *Faker) CarFuelType() string { return carFuelType(f.Rand) }
func carFuelType(r *rand.Rand) string { return getRandValue(r, []string{"car", "fuel_type"}) }
// CarTransmissionType will return a random transmission type
func CarTransmissionType() string { return carTransmissionType(globalFaker.Rand) }
// CarTransmissionType will return a random transmission type
func (f *Faker) CarTransmissionType() string { return carTransmissionType(f.Rand) }
func carTransmissionType(r *rand.Rand) string {
return getRandValue(r, []string{"car", "transmission_type"})
}
// CarMaker will return a random car maker
func CarMaker() string { return carMaker(globalFaker.Rand) }
// CarMaker will return a random car maker
func (f *Faker) CarMaker() string { return carMaker(f.Rand) }
func carMaker(r *rand.Rand) string { return getRandValue(r, []string{"car", "maker"}) }
// CarModel will return a random car model
func CarModel() string { return carModel(globalFaker.Rand) }
// CarModel will return a random car model
func (f *Faker) CarModel() string { return carModel(f.Rand) }
func carModel(r *rand.Rand) string { return getRandValue(r, []string{"car", "model"}) }
func addCarLookup() {
AddFuncLookup("car", Info{
Display: "Car",
Category: "car",
Description: "Random car set of data",
Output: "map[string]interface",
ContentType: "application/json",
Example: `{type: "Passenger car mini", fuel: "Gasoline", transmission: "Automatic", brand: "Fiat", model: "Freestyle Fwd", year: "1972"}`,
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return car(r), nil
},
})
AddFuncLookup("cartype", Info{
Display: "Car Type",
Category: "car",
Description: "Random car type",
Example: "Passenger car mini",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return carType(r), nil
},
})
AddFuncLookup("carfueltype", Info{
Display: "Car Fuel Type",
Category: "car",
Description: "Random car fuel type",
Example: "CNG",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return carFuelType(r), nil
},
})
AddFuncLookup("cartransmissiontype", Info{
Display: "Car Transmission Type",
Category: "car",
Description: "Random car transmission type",
Example: "Manual",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return carTransmissionType(r), nil
},
})
AddFuncLookup("carmaker", Info{
Display: "Car Maker",
Category: "car",
Description: "Random car maker",
Example: "Nissan",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return carMaker(r), nil
},
})
AddFuncLookup("carmodel", Info{
Display: "Car Model",
Category: "car",
Description: "Random car model",
Example: "Aveo",
Output: "string",
Generate: func(r *rand.Rand, m *MapParams, info *Info) (interface{}, error) {
return carModel(r), nil
},
})
}