func serveAsset(path string, c *gin.Context) { buff, err := server.Asset(path) if err != nil { c.String(400, err.Error()) return } c.Data(200, assetContentType(path), buff) }
func (p *Render) Render(w http.ResponseWriter, code int, data ...interface{}) error { file := "templates/" + data[0].(string) ctx := data[1].(pongo2.Context) var t *pongo2.Template if tmpl, ok := p.cache[file]; ok { t = tmpl } else { if options.Debug { tmpl, err := pongo2.FromFile(file) if err != nil { return err } t = tmpl } else { buff, err := server.Asset(file) if err == nil { tmpl, err := pongo2.FromString(string(buff)) if err != nil { return err } t = tmpl } else { tmpl, err := pongo2.FromFile(file) if err != nil { return err } t = tmpl } } p.cache[file] = t } writeHeader(w, code, "text/html") return t.ExecuteWriter(ctx, w) }