Skip to content
/ bip Public

Wrapper of pongo2.TemplateSet for go-bindata

License

Notifications You must be signed in to change notification settings

kudohamu/bip

Repository files navigation

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

package main

import (
  ...
)

var tplSet *bip.TemplateSet
var indexTpl bip.Template

func init() {
  tplSet = bip.NewSet(asset.Asset) // asset is a package generated from bindata.
  indexTpl = bip.Must(tplSet.FromFile("index.html"))
}

func main() {
  http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    if err := indexTpl.ExecuteWriter(bip.Context{}, w); err != nil {
      fmt.Fprintf(w, err.Error())
    }
  })
  http.ListenAndServe(":8080", nil)
}

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

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

Caution

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

About

Wrapper of pongo2.TemplateSet for go-bindata

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages