iris/_examples/view/template_jet_1_embedded/main.go
Gerasimos (Makis) Maropoulos c3205dafa1 New DirOptions.Cache field for in-memory caching and pre-compression for the fastest possible static file server
Read HISTORY.md it contains a breaking change, second parameter of HandleDir should be iris.Dir(...) instead of just a string

relative to: https://github.com/kataras/iris/issues/1556#issuecomment-661057446


Former-commit-id: 14b48a06fb3b99287dff543932be2937a64233b9
2020-07-24 13:03:49 +03:00

35 lines
1021 B
Go

// Package main shows how to use jet templates embedded in your application with ease using the Iris built-in Jet view engine.
// This example is a customized fork of https://github.com/CloudyKit/jet/tree/master/examples/asset_packaging, so you can
// notice the differences side by side. For example, you don't have to use any external package inside your application,
// Iris manually builds the template loader for binary data when Asset and AssetNames are available via tools like the go-bindata.
package main
import (
"os"
"strings"
"github.com/kataras/iris/v12"
)
// $ go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// $ go-bindata ./views/...
// $ go run .
func main() {
app := iris.New()
tmpl := iris.Jet("./views", ".jet").Binary(Asset, AssetNames)
app.RegisterView(tmpl)
app.Get("/", func(ctx iris.Context) {
ctx.View("index.jet")
})
port := os.Getenv("PORT")
if len(port) == 0 {
port = ":8080"
} else if !strings.HasPrefix(":", port) {
port = ":" + port
}
app.Listen(port)
}