-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
30 lines (25 loc) · 848 Bytes
/
server.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
package main
import (
"github.com/gorilla/mux"
h "goFruits/transport/http"
"log"
"net/http"
)
/*
func init() {
//m.Fruits = append(m.Fruits, m.Fruit{FruitName:"orange", Calories: 123, Price: 0.55})
//m.Fruits = append(m.Fruits, m.Fruit{FruitName:"apple", Calories: 100, Price: 0.85})
m.Fruits = m.LoadCSV()
fmt.Println("CSV loaded", m.Fruits)
}
*/
func main() {
r := mux.NewRouter()
api := r.PathPrefix("/api/v1").Subrouter()
api.HandleFunc("/fruit/{fruitName}", h.GetFruit).Methods(http.MethodGet)
api.HandleFunc("/fruit/{fruitName}", h.DeleteFruit).Methods(http.MethodDelete)
api.HandleFunc("/fruit", h.AddFruit).Methods(http.MethodPost)
api.HandleFunc("/fruit/{fruitName}", h.UpdateFruit).Methods(http.MethodPut)
api.HandleFunc("/fruits", h.GetAllFruits).Methods(http.MethodGet)
log.Fatal(http.ListenAndServe(":8080", r))
}