Thanks for the tutorial, I think there is a small bug here
w.WriteHeader(http.StatusOK) w.Header().Add("Content-Type", "application/json")
should be
w.Header().Add("Content-Type", "application/json") w.WriteHeader(http.StatusOK)
otherwise the content type header does not get written Another thing, I think you switched two lines
router.HandleFunc("/books/{id}", handlers.GetBook).Methods(http.MethodGet) // and router.HandleFunc("/books", handlers.AddBook).Methods(http.MethodPost)
between the two sections Add a new Book and Get a book by id
Add a new Book
Get a book by id
Thanks again for the great tutorial
Nice catch! Thanks, I have updated
hai sir good day can you help me with this thing .it was a code structure sir.
i edited all your codes and it comes with this error
"..\pkg\test\Additem.go:24:19: cannot use item (type models.Item) as type []byte in argument to json.Unmarshal"
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks for the tutorial, I think there is a small bug here
should be
otherwise the content type header does not get written
Another thing, I think you switched two lines
between the two sections
Add a new Book
andGet a book by id
Thanks again for the great tutorial
Nice catch! Thanks, I have updated
hai sir good day can you help me with this thing .it was a code structure sir.
i edited all your codes and it comes with this error
"..\pkg\test\Additem.go:24:19: cannot use item (type models.Item) as type []byte in argument to json.Unmarshal"