Common isomorphic functionality in one kit.

serversidehandlers.go 547B

123456789101112131415161718192021222324
  1. // +build !clientonly
  2. package isokit
  3. import (
  4. "bytes"
  5. "encoding/gob"
  6. "log"
  7. "net/http"
  8. )
  9. func TemplateBundleHandler(ts *TemplateSet) http.Handler {
  10. return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  11. var templateContentItemsBuffer bytes.Buffer
  12. enc := gob.NewEncoder(&templateContentItemsBuffer)
  13. m := ts.Bundle().Items()
  14. err := enc.Encode(&m)
  15. if err != nil {
  16. log.Print("encoding err: ", err)
  17. }
  18. w.Header().Set("Content-Type", "application/octet-stream")
  19. w.Write(templateContentItemsBuffer.Bytes())
  20. })
  21. }