func blockRenderer(content string, srange blackfriday.SourceRange, langAndParams string) (string, error) { lap := strings.Split(langAndParams, "|") language := lap[0] var class = "" var params = "" if len(lap) > 1 { class = lap[1] } if len(lap) > 2 { params = lap[2] } var r renderer var exists bool if r, exists = renderers[language]; !exists { return "", fmt.Errorf("Handle for language " + language + " does not exist") } if imgR, ok := r.(imageRenderer); ok { hasher := sha1.New() mustWriteString(hasher, content) sha1 := hasher.Sum(nil) ID := hex.EncodeToString(sha1[:]) filename := ID + "." + imgR.ImageFileExtension() if !store.ExistsCache(filename) { filenameWithPath := store.GetCachePath(filename) if err := imgR.RenderToFile(content, params, filenameWithPath); err != nil { return "", err } } imgloc := fmt.Sprintf("<img src=/cache/%s class=\""+class+"\" %s><br>", filename, srange.Attrs()) return imgloc, nil } divR := r.(divRenderer) rendered, err := divR.RenderToBuffer(content, params) if err != nil { return "", err } div := fmt.Sprintf("<div class=\""+class+"\" %s>%s</div><br>", srange.Attrs(), string(rendered)) return div, nil }
func doGETCache(c *gin.Context) { hash := normalize(c.Param("hash")) file := store.GetCachePath(hash) c.File(file) }