O'Reilly logo

Distributed Computing with Go by V.N. Nikhil Anurag

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

books-handler/common.go

The code in this source file is generic logic, which might be shared across multiple requests:

It is generally a good practice to identify the logic that is not tied to one particular handler and then move it into common.go or similar source files, as this would make them easier to find and reduce duplicated code.
// restServer/books-handler/common.go package booksHandler import ( "encoding/json" "fmt" "log" "net/http" ) // bookResource is used to hold all data needed to represent a Book resource in the books map. type bookResource struct { Id string 'json:"id"' Title string 'json:"title"' Link string 'json:"link"' } // requestPayload is used to parse request's Payload. We ignore Id field for simplicity. type requestPayload ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required