1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 18:37:05 +00:00

directly support embed.FS and fs.FS on view engines

This commit is contained in:
Gerasimos (Makis) Maropoulos
2022-09-21 23:26:12 +03:00
parent 5bc0796548
commit 95a8110f1e
12 changed files with 162 additions and 17 deletions

View File

@@ -1,15 +1,19 @@
package main
import "github.com/kataras/iris/v12"
import (
"embed"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/x/errors"
)
//go:embed templates/*
var embeddedTemplatesFS embed.FS
func main() {
app := iris.New()
// $ go install github.com/go-bindata/go-bindata/v3/go-bindata@latest
// $ go-bindata -fs -prefix "templates" ./templates/...
// $ go run .
// html files are not used, you can delete the folder and run the example.
tmpl := iris.HTML(AssetFile(), ".html")
tmpl := iris.HTML(embeddedTemplatesFS, ".html")
tmpl.Layout("layouts/layout.html")
tmpl.AddFunc("greet", func(s string) string {
return "Greetings " + s + "!"
@@ -19,8 +23,8 @@ func main() {
app.Get("/", func(ctx iris.Context) {
if err := ctx.View("page1.html"); err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.Writef(err.Error())
errors.InvalidArgument.Err(ctx, err)
return
}
})
@@ -28,8 +32,8 @@ func main() {
app.Get("/nolayout", func(ctx iris.Context) {
ctx.ViewLayout(iris.NoLayout)
if err := ctx.View("page1.html"); err != nil {
ctx.StatusCode(iris.StatusInternalServerError)
ctx.Writef(err.Error())
errors.InvalidArgument.Err(ctx, err)
return
}
})