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 product detail

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

package endpointsimport (  "encoding/json"  "net/http"  "github.com/EngineerKamesh/igb/igweb/common"  "github.com/gorilla/mux")func GetProductDetailEndpoint(env *common.Env) http.Handler {  return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {    vars := mux.Vars(r)    productTitle := vars["productTitle"]    products := env.DB.GetProductDetail(productTitle)    w.Header().Set("Content-Type", "application/json")    json.NewEncoder(w).Encode(products)  })}

Inside the GetProductDetailEndpoint function, we fetch embedded route variables, by calling the Vars function from the mux package and supplying the router object, r, as the sole input ...

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