func (r *Render) Render(w http.ResponseWriter, e Engine, data interface{}) error {
	err := e.Render(w, data)
	if err != nil && !r.opt.DisableHTTPErrorRendering {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
	return err
}
Render is the generic function called by XML, JSON, Data, HTML, and can be called by custom implementations.
package render
import (
	"bytes"
	"fmt"
	"html/template"
	"io/ioutil"
	"log"
	"net/http"
	"os"
	"path/filepath"
	"strings"
)
const (
	ContentBinary = "application/octet-stream"
	ContentHTML = "text/html"
	ContentJSON = "application/json"
	ContentJSONP = "application/javascript"
	ContentLength = "Content-Length"
	ContentText = "text/plain"
	ContentType = "Content-Type"
	ContentXHTML = "application/xhtml+xml"
	ContentXML = "text/xml"
	defaultCharset = "UTF-8"
)
type Delims struct {
	Left string
	Right string
}
type Options struct {
	Directory string
	Asset func(name string) ([]byte, error)
	AssetNames func() []string
	Layout string
	Extensions []string
	Funcs []template.FuncMap
	Delims Delims
	Charset string
	IndentJSON bool
	IndentXML bool
	PrefixJSON []byte
	PrefixXML []byte
	HTMLContentType string
	IsDevelopment bool
	UnEscapeHTML bool
	StreamingJSON bool
	RequirePartials bool
	RequireBlocks bool
	DisableHTTPErrorRendering bool
}
type HTMLOptions struct {
	Layout string
}
type Render struct {
	opt             Options
	templates       *template.Template
	compiledCharset string
}
func New(options ...Options) *Render {
	var o Options
	if len(options) == 0 {
		o = Options{}
	} else {
		o = options[0]
	}
	r := Render{
		opt: o,
	}
	r.prepareOptions()
	r.compileTemplates()
	if bufPool == nil {
		bufPool = NewBufferPool(64)
	}
	return &r
}
func (r *Render) prepareOptions() {
	if len(r.opt.Charset) == 0 {
		r.opt.Charset = defaultCharset
	}
	r.compiledCharset = "; charset=" + r.opt.Charset
	if len(r.opt.Directory) == 0 {
		r.opt.Directory = "templates"
	}
	if len(r.opt.Extensions) == 0 {
		r.opt.Extensions = []string{".tmpl"}
	}
	if len(r.opt.HTMLContentType) == 0 {
		r.opt.HTMLContentType = ContentHTML
	}
}
func (r *Render) compileTemplates() {
	if r.opt.Asset == nil || r.opt.AssetNames == nil {
		r.compileTemplatesFromDir()
		return
	}
	r.compileTemplatesFromAsset()
}
func (r *Render) compileTemplatesFromDir() {
	dir := r.opt.Directory
	r.templates = template.New(dir)
	r.templates.Delims(r.opt.Delims.Left, r.opt.Delims.Right)
	filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
		if info == nil || info.IsDir() {
			return nil
		}
		rel, err := filepath.Rel(dir, path)
		if err != nil {
			return err
		}
		ext := ""
		if strings.Index(rel, ".") != -1 {
			ext = filepath.Ext(rel)
		}
		for _, extension := range r.opt.Extensions {
			if ext == extension {
				buf, err := ioutil.ReadFile(path)
				if err != nil {
					panic(err)
				}
				name := (rel[0 : len(rel)-len(ext)])
				tmpl := r.templates.New(filepath.ToSlash(name))
				for _, funcs := range r.opt.Funcs {
					tmpl.Funcs(funcs)
				}
				template.Must(tmpl.Funcs(helperFuncs).Parse(string(buf)))
				break
			}
		}
		return nil
	})
}
func (r *Render) compileTemplatesFromAsset() {
	dir := r.opt.Directory
	r.templates = template.New(dir)
	r.templates.Delims(r.opt.Delims.Left, r.opt.Delims.Right)
	for _, path := range r.opt.AssetNames() {
		if !strings.HasPrefix(path, dir) {
			continue
		}
		rel, err := filepath.Rel(dir, path)
		if err != nil {
			panic(err)
		}
		ext := ""
		if strings.Index(rel, ".") != -1 {
			ext = "." + strings.Join(strings.Split(rel, ".")[1:], ".")
		}
		for _, extension := range r.opt.Extensions {
			if ext == extension {
				buf, err := r.opt.Asset(path)
				if err != nil {
					panic(err)
				}
				name := (rel[0 : len(rel)-len(ext)])
				tmpl := r.templates.New(filepath.ToSlash(name))
				for _, funcs := range r.opt.Funcs {
					tmpl.Funcs(funcs)
				}
				template.Must(tmpl.Funcs(helperFuncs).Parse(string(buf)))
				break
			}
		}
	}
}
func (r *Render) TemplateLookup(t string) *template.Template {
	return r.templates.Lookup(t)
}
func (r *Render) execute(name string, binding interface{}) (*bytes.Buffer, error) {
	buf := new(bytes.Buffer)
	return buf, r.templates.ExecuteTemplate(buf, name, binding)
}
func (r *Render) addLayoutFuncs(name string, binding interface{}) {
	funcs := template.FuncMap{
		"yield": func() (template.HTML, error) {
			buf, err := r.execute(name, binding)
			return template.HTML(buf.String()), err
		},
		"current": func() (string, error) {
			return name, nil
		},
		"block": func(partialName string) (template.HTML, error) {
			log.Print("Render's `block` implementation is now depericated. Use `partial` as a drop in replacement.")
			fullPartialName := fmt.Sprintf("%s-%s", partialName, name)
			if r.opt.RequireBlocks || r.TemplateLookup(fullPartialName) != nil {
				buf, err := r.execute(fullPartialName, binding)
				return template.HTML(buf.String()), err
			}
			return "", nil
		},
		"partial": func(partialName string) (template.HTML, error) {
			fullPartialName := fmt.Sprintf("%s-%s", partialName, name)
			if r.opt.RequirePartials || r.TemplateLookup(fullPartialName) != nil {
				buf, err := r.execute(fullPartialName, binding)
				return template.HTML(buf.String()), err
			}
			return "", nil
		},
	}
	if tpl := r.templates.Lookup(name); tpl != nil {
		tpl.Funcs(funcs)
	}
}
func (r *Render) prepareHTMLOptions(htmlOpt []HTMLOptions) HTMLOptions {
	if len(htmlOpt) > 0 {
		return htmlOpt[0]
	}
	return HTMLOptions{
		Layout: r.opt.Layout,
	}
}