2019-06-22 20:34:19 +02:00
|
|
|
// 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"
|
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
2019-06-22 20:34:19 +02:00
|
|
|
)
|
|
|
|
|
2022-07-19 21:48:04 +02:00
|
|
|
// $ go install github.com/go-bindata/go-bindata/v3/go-bindata@latest
|
2020-09-05 07:34:09 +02:00
|
|
|
//
|
|
|
|
// $ go-bindata -fs -prefix "views" ./views/...
|
2020-07-06 20:40:40 +02:00
|
|
|
// $ go run .
|
2020-09-05 07:34:09 +02:00
|
|
|
//
|
|
|
|
// System files are not used, you can optionally delete the folder and run the example now.
|
2019-06-22 20:34:19 +02:00
|
|
|
func main() {
|
|
|
|
app := iris.New()
|
2020-09-05 07:34:09 +02:00
|
|
|
tmpl := iris.Jet(AssetFile(), ".jet")
|
2019-06-22 20:34:19 +02:00
|
|
|
app.RegisterView(tmpl)
|
|
|
|
|
|
|
|
app.Get("/", func(ctx iris.Context) {
|
2022-12-13 00:37:15 +01:00
|
|
|
if err := ctx.View("index.jet"); err != nil {
|
|
|
|
ctx.HTML("<h3>%s</h3>", err.Error())
|
|
|
|
return
|
|
|
|
}
|
2019-06-22 20:34:19 +02:00
|
|
|
})
|
|
|
|
|
2020-09-05 07:34:09 +02:00
|
|
|
addr := ":8080"
|
|
|
|
if port := os.Getenv("PORT"); port != "" {
|
|
|
|
addr = ":" + port
|
2019-06-22 20:34:19 +02:00
|
|
|
}
|
|
|
|
|
2020-09-05 07:34:09 +02:00
|
|
|
app.Listen(addr)
|
2019-06-22 20:34:19 +02:00
|
|
|
}
|