I am following a tutorial to great an API in Go with a framework called Gin.

I have imported errors and created a function like so;

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 is as follows;

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")

}

If i simply ignore the import error I get this;

[GIN-debug] Listening and serving HTTP on localhost:8080

[GIN-debug] [ERROR] listen tcp 127.0.0.1:8080: bind: address already in use

I've gone over the tutorial several times and I'm not sure how he isn't
getting the erros.

On another note are there any good recommendations for documentation to
create an API without a framework?

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAPp9YQWGyicjMrFrMD2yg4Sb%2BLMGFFzGq_aKbRf25iLv2YW1Nw%40mail.gmail.com.

Reply via email to