func createBook(c *gin.Context) {
var newBook book
if err := c.BindJSON(&newBook); err != nil {
return
}
books = append(books, newBook)
c.IndentedJSON(http.StatusCreated, newBook)
}
func main() {
//1.router responsible for handling different routes and diff endpoints of API
router := gin.Default()
//2.the route we are handling is /books, ie when u go to localhost:8080/books it will call getBooks()function
router.GET("/books", getBooks)
router.POST("/books", createBook)
router.Run("localhost:8080")
}
[GIN-debug] Listening and serving HTTP on localhost:8080
[GIN-debug] [ERROR] listen tcp 127.0.0.1:8080: bind: address already in use
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAPp9YQWGyicjMrFrMD2yg4Sb%2BLMGFFzGq_aKbRf25iLv2YW1Nw%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAPp9YQWGyicjMrFrMD2yg4Sb%2BLMGFFzGq_aKbRf25iLv2YW1Nw%40mail.gmail.com.