ray-g / go-bindata-template

Extends Golang's HTML templates to read from go-bindata

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-bindata-template

About go-bindata-template

go-bindata-template extends Go's built-in html/template to load and parse embeded template content instead of filesystem packaged by go-bindata jteeuwen/go-bindata or a bit newer kevenburke/go-bindata.

Override Parse and ParseFiles to parse embeded contents. Added ParseDir and ParseAll for convenice.

Example

(Suppose your data are under data folder and after running go-bindata data/...)

import (
    template "github.com/ray-g/go-bindata-template"
)

func someHandler(w http.ResponseWriter, r *http.Request) {
    tmpl, err := template.New("index", &template.BinData{
        Asset: Asset,
        AssetDir: AssetDir,
        AssetNames: AssetNames,
    }).Parse("data/index.tmpl")

    if err != nil {
        log.Fatalf("error parsing template: %s", err)
    }

    err = tmpl.Execute(w)

    if err != nil {
        log.Fatalf("error execute template: %s", err)
    }
}

More detail usages can be found here

About

Extends Golang's HTML templates to read from go-bindata

License:MIT License


Languages

Language:Go 95.0%Language:Shell 5.0%