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 add items to the shopping cart

We declared a m variable (shown in bold), of the map[string]string type, in AddItemToShoppingCartEndpoint, which is the endpoint function that is responsible for adding a new item to the shopping cart:

func AddItemToShoppingCartEndpoint(env *common.Env) http.Handler {  return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {    igwSession, _ := env.Store.Get(r, "igweb-session")    decoder := json.NewDecoder(r.Body)    var m map[string]string    err := decoder.Decode(&m)    if err != nil {      log.Print("Encountered error when attempting to decode json data from request body: ", err)    }    defer r.Body.Close()    var cart *models.ShoppingCart

We use a JSON decoder to decode the request body, which will contain ...

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