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

Serving the template bundle items

Here's the TemplateBundleHandler function found in the templatebundle.go source file in the handlers folder:

func TemplateBundleHandler(env *common.Env) http.Handler {  return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {    var templateContentItemsBuffer bytes.Buffer    enc := gob.NewEncoder(&templateContentItemsBuffer)    m := env.TemplateSet.Bundle().Items()    err := enc.Encode(&m)    if err != nil {      log.Print("encoding err: ", err)    }    w.Header().Set("Content-Type", "application/octet-stream")    w.Write(templateContentItemsBuffer.Bytes())  })}

The code to encode data to gob format should look familiar, it's just like how we encoded the cars slice to gob format in the Transmitting gob encoded data section ...

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