March 2019
Beginner to intermediate
324 pages
7h 17m
English
After creating our handlers, let's go back to ./backend/src/rest/rest.go. Instead of mapping our routes to empty handlers, let's map our routes to the handlers that we created in the previous section:
func RunAPI(address string) error { //Get gin's default engine r := gin.Default() //Define a handler h, _ := NewHandler() //get products r.GET("/products", h.GetProducts) //get promos r.GET("/promos", h.GetPromos) //post user sign in r.POST("/users/signin", h.SignIn) //add a user r.POST("/users",h.AddUser) //post user sign out r.POST("/user/:id/signout", h.SignOut) //get user orders r.GET("/user/:id/orders", h.GetOrders) //post purchase charge r.POST("/users/charge", h.Charge) //run the server return r.Run(address)}Read now
Unlock full access