项目作者: kudohamu

项目描述 :
Wrapper of pongo2.TemplateSet for go-bindata
高级语言: Go
项目地址: git://github.com/kudohamu/bip.git
创建时间: 2017-07-01T10:39:31Z
项目社区:https://github.com/kudohamu/bip

开源协议:MIT License

下载


bip

Wrapper of pongo2.TemplateSet for go-bindata

GoDoc
License: MIT

Motivation

When use go-bindata and pongo2 in combination, it is troublesome to build every time rewrite views (even using Must).
So bip behaves what read from files every executions when in development, and read from bindata when in production.

Usage

  1. package main
  2. import (
  3. ...
  4. )
  5. var tplSet *bip.TemplateSet
  6. var indexTpl bip.Template
  7. func init() {
  8. tplSet = bip.NewSet(asset.Asset) // asset is a package generated from bindata.
  9. indexTpl = bip.Must(tplSet.FromFile("index.html"))
  10. }
  11. func main() {
  12. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  13. if err := indexTpl.ExecuteWriter(bip.Context{}, w); err != nil {
  14. fmt.Fprintf(w, err.Error())
  15. }
  16. })
  17. http.ListenAndServe(":8080", nil)
  18. }

if you use as production binary, you need to add bip to build tag.

  1. $ go build -tags="bip ...other tags"

Caution

bip depends on master of pongo2. DO NOT use v3.