-
-
Notifications
You must be signed in to change notification settings - Fork 263
/
car.go
146 lines (121 loc) · 4.38 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
142
143
144
145
146
package gofakeit
// 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) }
// Car will generate a struct with car information
func (f *Faker) Car() *CarInfo { return car(f) }
func car(f *Faker) *CarInfo {
return &CarInfo{
Type: carType(f),
Fuel: carFuelType(f),
Transmission: carTransmissionType(f),
Brand: carMaker(f),
Model: carModel(f),
Year: year(f),
}
}
// CarType will generate a random car type string
func CarType() string { return carType(GlobalFaker) }
// CarType will generate a random car type string
func (f *Faker) CarType() string { return carType(f) }
func carType(f *Faker) string { return getRandValue(f, []string{"car", "type"}) }
// CarFuelType will return a random fuel type
func CarFuelType() string { return carFuelType(GlobalFaker) }
// CarFuelType will return a random fuel type
func (f *Faker) CarFuelType() string { return carFuelType(f) }
func carFuelType(f *Faker) string { return getRandValue(f, []string{"car", "fuel_type"}) }
// CarTransmissionType will return a random transmission type
func CarTransmissionType() string { return carTransmissionType(GlobalFaker) }
// CarTransmissionType will return a random transmission type
func (f *Faker) CarTransmissionType() string { return carTransmissionType(f) }
func carTransmissionType(f *Faker) string {
return getRandValue(f, []string{"car", "transmission_type"})
}
// CarMaker will return a random car maker
func CarMaker() string { return carMaker(GlobalFaker) }
// CarMaker will return a random car maker
func (f *Faker) CarMaker() string { return carMaker(f) }
func carMaker(f *Faker) string { return getRandValue(f, []string{"car", "maker"}) }
// CarModel will return a random car model
func CarModel() string { return carModel(GlobalFaker) }
// CarModel will return a random car model
func (f *Faker) CarModel() string { return carModel(f) }
func carModel(f *Faker) string { return getRandValue(f, []string{"car", "model"}) }
func addCarLookup() {
AddFuncLookup("car", Info{
Display: "Car",
Category: "car",
Description: "Wheeled motor vehicle used for transportation",
Example: `{
"type": "Passenger car mini",
"fuel": "Gasoline",
"transmission": "Automatic",
"brand": "Fiat",
"model": "Freestyle Fwd",
"year": 1991
}`,
Output: "map[string]any",
ContentType: "application/json",
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
return car(f), nil
},
})
AddFuncLookup("cartype", Info{
Display: "Car Type",
Category: "car",
Description: "Classification of cars based on size, use, or body style",
Example: "Passenger car mini",
Output: "string",
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
return carType(f), nil
},
})
AddFuncLookup("carfueltype", Info{
Display: "Car Fuel Type",
Category: "car",
Description: "Type of energy source a car uses",
Example: "CNG",
Output: "string",
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
return carFuelType(f), nil
},
})
AddFuncLookup("cartransmissiontype", Info{
Display: "Car Transmission Type",
Category: "car",
Description: "Mechanism a car uses to transmit power from the engine to the wheels",
Example: "Manual",
Output: "string",
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
return carTransmissionType(f), nil
},
})
AddFuncLookup("carmaker", Info{
Display: "Car Maker",
Category: "car",
Description: "Company or brand that manufactures and designs cars",
Example: "Nissan",
Output: "string",
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
return carMaker(f), nil
},
})
AddFuncLookup("carmodel", Info{
Display: "Car Model",
Category: "car",
Description: "Specific design or version of a car produced by a manufacturer",
Example: "Aveo",
Output: "string",
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
return carModel(f), nil
},
})
}