func printPresentation(path string) { pres, err := gosrc.GetPresentation(http.DefaultClient, path) if err != nil { log.Fatal(err) } fmt.Printf("%s\n", pres.Files[pres.Filename]) for name, data := range pres.Files { if name != pres.Filename { fmt.Printf("---------- %s ----------\n%s\n", name, data) } } }
func servePresentation(w http.ResponseWriter, r *http.Request) error { c := appengine.NewContext(r) importPath := r.URL.Path[1:] item, err := memcache.Get(c, importPath) if err == nil { writeHTMLHeader(w, 200) w.Write(item.Value) return nil } else if err != memcache.ErrCacheMiss { return err } c.Infof("Fetching presentation %s.", importPath) pres, err := gosrc.GetPresentation(httpClient(r), importPath) if err != nil { return err } ctx := &present.Context{ ReadFile: func(name string) ([]byte, error) { if p, ok := pres.Files[name]; ok { return p, nil } return nil, presFileNotFoundError(name) }, } doc, err := ctx.Parse(bytes.NewReader(pres.Files[pres.Filename]), pres.Filename, 0) if err != nil { return err } var buf bytes.Buffer if err := renderPresentation(&buf, importPath, doc); err != nil { return err } if err := memcache.Add(c, &memcache.Item{ Key: importPath, Value: buf.Bytes(), Expiration: time.Hour, }); err != nil { return err } writeHTMLHeader(w, 200) _, err = w.Write(buf.Bytes()) return err }