O'Reilly logo

Isomorphic Go by Kamesh Balasubramanian

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

The endpoint to get the list of products

Let's examine the products.go source file in the endpoints folder:

package endpointsimport (  "encoding/json"  "net/http"  "github.com/EngineerKamesh/igb/igweb/common")func GetProductsEndpoint(env *common.Env) http.Handler {  return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {    products := env.DB.GetProducts()    w.Header().Set("Content-Type", "application/json")    json.NewEncoder(w).Encode(products)  })}

Inside the GetProductsEndpoint function, we first fetch the slice of products that will be displayed on the client-side products page by calling the GetProducts method of the datastore object, env.DB. We then set a header to indicate that the server response will be in JSON format. Finally, ...

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