-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdealership.go
49 lines (42 loc) · 1 KB
/
dealership.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
type autoDealership struct {
//variable fields defined here
d map[string]int
}
func newAutoDealership() autoDealership {
//creating instance of autoDealership class
d := make(map[string]int)
return autoDealership{d: d}
func addCar() {
//code to add car
item := r.URL.Query().Get("car")
count := r.URL.Query().Get("count")
if item != "" && count != "" {
c.d[car] = count
}
func removeCar() {
//code to remove car
item := r.URL.Query().Get("car")
count := r.URL.Query().Get("count")
if item != "" && count != "" {
del c.d[car]
}
func listCar() {
//code to list car
fmt.Fprintln(w, "Car", "Count")
for key, value := c.d {
fmt.Fprintln(w, key, " ", value)
}
}
}
var c autoDealership
func main() {
//call each function here
c = newAutoDealership()
if r.URL.Path == "/catalog/add" {
addCar(w, r)
} else if r.URL.Path == "/catalog/list" {
listCar(w, r)
} else if r.URL.Path == "/catalog/remove" {
removeCar(w, r)
}
}