Exemplo n.º 1
0
Arquivo: print.go Projeto: AlekSi/gddo
func printPresentation(path string) {
	pres, err := doc.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)
		}
	}
}
Exemplo n.º 2
0
Arquivo: main.go Projeto: AlekSi/gddo
func servePresentation(resp web.Response, req *web.Request) error {
	if p := path.Clean(req.URL.Path); p != req.URL.Path {
		return web.Redirect(resp, req, p, 301, nil)
	}

	presMu.Lock()
	for p, pres := range presentations {
		if time.Since(pres.Updated) > 15*time.Minute {
			delete(presentations, p)
		}
	}
	p := req.RouteVars["path"]
	pres := presentations[p]
	presMu.Unlock()

	if pres == nil {
		var err error
		log.Println("Fetch presentation ", p)
		pres, err = doc.GetPresentation(httpClient, p)
		if err != nil {
			return err
		}
		presMu.Lock()
		presentations[p] = pres
		presMu.Unlock()
	}
	ctx := &present.Context{
		ReadFile: func(name string) ([]byte, error) {
			if p, ok := pres.Files[name]; ok {
				return p, nil
			}
			return nil, fmt.Errorf("pres file not found %s", name)
		},
	}
	doc, err := ctx.Parse(bytes.NewReader(pres.Files[pres.Filename]), pres.Filename, 0)
	if err != nil {
		return err
	}
	return renderPresentation(resp, p, doc)
}