diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml
index f9444ac..805c0e9 100644
--- a/.github/workflows/benchmark.yml
+++ b/.github/workflows/benchmark.yml
@@ -32,7 +32,7 @@ jobs:
uses: actions/setup-go@v5
with:
# NOTE: Keep this in sync with the version from go.mod
- go-version: "1.20.x"
+ go-version: "1.25.x"
cache: false
- name: Run Benchmarks
diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml
index 204a32d..63c7707 100644
--- a/.github/workflows/golangci-lint.yml
+++ b/.github/workflows/golangci-lint.yml
@@ -34,10 +34,12 @@ jobs:
uses: actions/setup-go@v5
with:
# NOTE: Keep this in sync with the version from go.mod
- go-version: '1.20.x'
+ go-version: '1.25.x'
cache: false
- name: golangci-lint
- uses: golangci/golangci-lint-action@v6
+ uses: golangci/golangci-lint-action@v7
+ env:
+ GOLANGCI_LINT_SKIP_GOVERSION_CHECK: "1"
with:
# NOTE: Keep this in sync with the version from .golangci.yml
- version: 'v1.56.2'
+ version: 'v2.5.0'
diff --git a/.github/workflows/gosec.yml b/.github/workflows/gosec.yml
index eace6b8..553afcd 100644
--- a/.github/workflows/gosec.yml
+++ b/.github/workflows/gosec.yml
@@ -55,7 +55,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
- go-version: '^1.21.x'
+ go-version: '1.25.x'
check-latest: true
cache: false
- name: Install gosec
diff --git a/.github/workflows/govulncheck.yml b/.github/workflows/govulncheck.yml
index 854ce3b..ebf589c 100644
--- a/.github/workflows/govulncheck.yml
+++ b/.github/workflows/govulncheck.yml
@@ -1,39 +1,39 @@
-name: Govulncheck Security Scan
-
-on:
- push:
- branches:
- - "master"
- - "main"
- paths-ignore:
- - "**.md"
- - LICENSE
- - ".github/ISSUE_TEMPLATE/*.yml"
- - ".github/dependabot.yml"
- pull_request:
- branches:
- - "*"
- paths-ignore:
- - "**.md"
- - LICENSE
- - ".github/ISSUE_TEMPLATE/*.yml"
- - ".github/dependabot.yml"
-
-jobs:
- govulncheck-check:
- runs-on: ubuntu-latest
- env:
- GO111MODULE: on
- steps:
- - name: Fetch Repository
- uses: actions/checkout@v5
- - name: Install Go
- uses: actions/setup-go@v5
- with:
- go-version: 'stable'
- check-latest: true
- cache: false
- - name: Install Govulncheck
- run: go install golang.org/x/vuln/cmd/govulncheck@latest
- - name: Run Govulncheck
- run: govulncheck ./...
\ No newline at end of file
+name: Govulncheck Security Scan
+
+on:
+ push:
+ branches:
+ - "master"
+ - "main"
+ paths-ignore:
+ - "**.md"
+ - LICENSE
+ - ".github/ISSUE_TEMPLATE/*.yml"
+ - ".github/dependabot.yml"
+ pull_request:
+ branches:
+ - "*"
+ paths-ignore:
+ - "**.md"
+ - LICENSE
+ - ".github/ISSUE_TEMPLATE/*.yml"
+ - ".github/dependabot.yml"
+
+jobs:
+ govulncheck-check:
+ runs-on: ubuntu-latest
+ env:
+ GO111MODULE: on
+ steps:
+ - name: Fetch Repository
+ uses: actions/checkout@v5
+ - name: Install Go
+ uses: actions/setup-go@v5
+ with:
+ go-version: '1.25.x'
+ check-latest: false
+ cache: false
+ - name: Install Govulncheck
+ run: go install golang.org/x/vuln/cmd/govulncheck@latest
+ - name: Run Govulncheck
+ run: govulncheck ./...
diff --git a/.github/workflows/test-ace.yml b/.github/workflows/test-ace.yml
index d401dd0..c274c97 100644
--- a/.github/workflows/test-ace.yml
+++ b/.github/workflows/test-ace.yml
@@ -16,12 +16,7 @@ jobs:
strategy:
matrix:
go-version:
- - 1.17.x
- - 1.18.x
- - 1.19.x
- - 1.20.x
- - 1.21.x
- - 1.22.x
+ - 1.25.x
platform: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.platform }}
steps:
diff --git a/.github/workflows/test-amber.yml b/.github/workflows/test-amber.yml
index 9589037..256fa1c 100644
--- a/.github/workflows/test-amber.yml
+++ b/.github/workflows/test-amber.yml
@@ -16,12 +16,7 @@ jobs:
strategy:
matrix:
go-version:
- - 1.17.x
- - 1.18.x
- - 1.19.x
- - 1.20.x
- - 1.21.x
- - 1.22.x
+ - 1.25.x
platform: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.platform }}
steps:
diff --git a/.github/workflows/test-django.yml b/.github/workflows/test-django.yml
index 07e35cb..b756dd4 100644
--- a/.github/workflows/test-django.yml
+++ b/.github/workflows/test-django.yml
@@ -16,11 +16,7 @@ jobs:
strategy:
matrix:
go-version:
- - 1.18.x
- - 1.19.x
- - 1.20.x
- - 1.21.x
- - 1.22.x
+ - 1.25.x
platform: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.platform }}
steps:
diff --git a/.github/workflows/test-handlebars.yml b/.github/workflows/test-handlebars.yml
index b4997d2..b1e8558 100644
--- a/.github/workflows/test-handlebars.yml
+++ b/.github/workflows/test-handlebars.yml
@@ -16,12 +16,7 @@ jobs:
strategy:
matrix:
go-version:
- - 1.17.x
- - 1.18.x
- - 1.19.x
- - 1.20.x
- - 1.21.x
- - 1.22.x
+ - 1.25.x
platform: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.platform }}
steps:
diff --git a/.github/workflows/test-html.yml b/.github/workflows/test-html.yml
index 43096d3..7c7ce6c 100644
--- a/.github/workflows/test-html.yml
+++ b/.github/workflows/test-html.yml
@@ -16,12 +16,7 @@ jobs:
strategy:
matrix:
go-version:
- - 1.17.x
- - 1.18.x
- - 1.19.x
- - 1.20.x
- - 1.21.x
- - 1.22.x
+ - 1.25.x
platform: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.platform }}
steps:
diff --git a/.github/workflows/test-jet.yml b/.github/workflows/test-jet.yml
index f508dd5..7b2763a 100644
--- a/.github/workflows/test-jet.yml
+++ b/.github/workflows/test-jet.yml
@@ -16,12 +16,7 @@ jobs:
strategy:
matrix:
go-version:
- - 1.17.x
- - 1.18.x
- - 1.19.x
- - 1.20.x
- - 1.21.x
- - 1.22.x
+ - 1.25.x
platform: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.platform }}
steps:
diff --git a/.github/workflows/test-mustache.yml b/.github/workflows/test-mustache.yml
index c0cc1bd..554226d 100644
--- a/.github/workflows/test-mustache.yml
+++ b/.github/workflows/test-mustache.yml
@@ -16,12 +16,7 @@ jobs:
strategy:
matrix:
go-version:
- - 1.17.x
- - 1.18.x
- - 1.19.x
- - 1.20.x
- - 1.21.x
- - 1.22.x
+ - 1.25.x
platform: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.platform }}
steps:
diff --git a/.github/workflows/test-pug.yml b/.github/workflows/test-pug.yml
index 575e28a..a46536e 100644
--- a/.github/workflows/test-pug.yml
+++ b/.github/workflows/test-pug.yml
@@ -16,12 +16,7 @@ jobs:
strategy:
matrix:
go-version:
- - 1.17.x
- - 1.18.x
- - 1.19.x
- - 1.20.x
- - 1.21.x
- - 1.22.x
+ - 1.25.x
platform: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.platform }}
steps:
diff --git a/.github/workflows/test-slim.yml b/.github/workflows/test-slim.yml
index bbd43f0..d9ab839 100644
--- a/.github/workflows/test-slim.yml
+++ b/.github/workflows/test-slim.yml
@@ -16,12 +16,7 @@ jobs:
strategy:
matrix:
go-version:
- - 1.17.x
- - 1.18.x
- - 1.19.x
- - 1.20.x
- - 1.21.x
- - 1.22.x
+ - 1.25.x
platform: [ ubuntu-latest, windows-latest ]
runs-on: ${{ matrix.platform }}
steps:
diff --git a/.golangci.yml b/.golangci.yml
index a5b91d7..2acbf7a 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -1,164 +1,10 @@
-# Created based on v1.56.1
-# NOTE: Keep this in sync with the version in .github/workflows/linter.yml
+# Created for golangci-lint v2.5.0
+# NOTE: Keep this in sync with the version in .github/workflows/golangci-lint.yml
+
+version: "2"
run:
modules-download-mode: readonly
- skip-dirs-use-default: false
- skip-dirs:
- - internal
-
-output:
- sort-results: true
-
-linters-settings:
- errcheck:
- check-type-assertions: true
- check-blank: true
- disable-default-exclusions: true
- exclude-functions:
- - '(*bytes.Buffer).Write' # always returns nil error
- - '(*github.com/valyala/bytebufferpool.ByteBuffer).Write' # always returns nil error
- - '(*github.com/valyala/bytebufferpool.ByteBuffer).WriteByte' # always returns nil error
- - '(*github.com/valyala/bytebufferpool.ByteBuffer).WriteString' # always returns nil error
-
- errchkjson:
- report-no-exported: true
-
- exhaustive:
- default-signifies-exhaustive: true
-
- forbidigo:
- forbid:
- - ^(fmt\.Print(|f|ln)|print|println)$
- - 'http\.Default(Client|Transport)'
- # TODO: Eventually enable these patterns
- # - 'time\.Sleep'
- # - 'panic'
-
- gocritic:
- disabled-checks:
- - ifElseChain
-
- gofumpt:
- module-path: github.com/gofiber/template
- extra-rules: true
-
- gosec:
- excludes:
- - G104 # Provided by errcheck
- config:
- global:
- audit: true
-
- depguard:
- rules:
- main:
- deny:
- - pkg: flag
- desc: '`flag` package is only allowed in main.go'
- - pkg: io/ioutil
- desc: '`io/ioutil` package is deprecated, use the `io` and `os` package instead'
-
- govet:
- check-shadowing: true
- enable-all: true
- disable:
- - shadow
- - fieldalignment
- - loopclosure
-
- grouper:
- import-require-single-import: true
- import-require-grouping: true
-
- misspell:
- locale: US
-
- nolintlint:
- require-explanation: true
- require-specific: true
-
- nonamedreturns:
- report-error-in-defer: true
-
- predeclared:
- q: true
-
- promlinter:
- strict: true
-
- revive:
- enable-all-rules: true
- rules:
- # Provided by gomnd linter
- - name: add-constant
- disabled: true
- - name: argument-limit
- disabled: true
- # Provided by bidichk
- - name: banned-characters
- disabled: true
- - name: cognitive-complexity
- disabled: true
- - name: comment-spacings
- disabled: true # TODO https://github.com/gofiber/fiber/issues/2816
- - name: cyclomatic
- disabled: true
- - name: early-return
- severity: warning
- disabled: true
- - name: exported
- disabled: true
- - name: file-header
- disabled: true
- - name: function-result-limit
- disabled: true
- - name: function-length
- disabled: true
- - name: line-length-limit
- disabled: true
- - name: max-public-structs
- disabled: true
- - name: modifies-parameter
- disabled: true
- - name: nested-structs
- disabled: true
- - name: package-comments
- disabled: true
- - name: unchecked-type-assertion
- disabled: true # TODO https://github.com/gofiber/fiber/issues/2816
- # Provided by errcheck
- - name: unhandled-error
- disabled: true
- - name: use-any # TODO Enable for v3 release
- disabled: true
-
- stylecheck:
- checks:
- - all
- - -ST1000
- - -ST1020
- - -ST1021
- - -ST1022
-
- tagliatelle:
- case:
- rules:
- json: snake
-
- tenv:
- all: true
-
- #unparam:
- # check-exported: true
-
- wrapcheck:
- ignorePackageGlobs:
- - github.com/gofiber/fiber/*
- - github.com/valyala/fasthttp
-
-issues:
- exclude-use-default: false
linters:
disable:
@@ -177,21 +23,16 @@ linters:
- errchkjson
- errname
- errorlint
- - execinquery
- exhaustive
- - exportloopref
+ - copyloopvar
- forbidigo
- forcetypeassert
- gochecksumtype
- goconst
- gocritic
- - gofmt
- - gofumpt
- - goimports
- gomoddirectives
- goprintffuncname
- gosec
- - gosimple
- gosmopolitan
- govet
- grouper
@@ -209,24 +50,138 @@ linters:
- perfsprint
- predeclared
- promlinter
- - reassign
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- - stylecheck
- tagalign
- tagliatelle
- testifylint
- testpackage
- thelper
- tparallel
- - typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
+ - unqueryvet
- wrapcheck
- - tenv
+ settings:
+ errcheck:
+ check-type-assertions: true
+ check-blank: true
+ disable-default-exclusions: true
+ exclude-functions:
+ - '(*bytes.Buffer).Write'
+ - '(*github.com/valyala/bytebufferpool.ByteBuffer).Write'
+ - '(*github.com/valyala/bytebufferpool.ByteBuffer).WriteByte'
+ - '(*github.com/valyala/bytebufferpool.ByteBuffer).WriteString'
+ errchkjson:
+ report-no-exported: true
+ exhaustive:
+ default-signifies-exhaustive: true
+ forbidigo:
+ forbid:
+ - pattern: ^(fmt\.Print(|f|ln)|print|println)$
+ - pattern: 'http\.Default(Client|Transport)'
+ gocritic:
+ disabled-checks:
+ - ifElseChain
+ gosec:
+ excludes:
+ - G104
+ config:
+ global:
+ audit: true
+ depguard:
+ rules:
+ main:
+ deny:
+ - pkg: flag
+ desc: '`flag` package is only allowed in main.go'
+ - pkg: io/ioutil
+ desc: '`io/ioutil` package is deprecated, use the `io` and `os` package instead'
+ govet:
+ enable-all: true
+ disable:
+ - shadow
+ - fieldalignment
+ - loopclosure
+ grouper:
+ import-require-single-import: true
+ import-require-grouping: true
+ misspell:
+ locale: US
+ nolintlint:
+ require-explanation: true
+ require-specific: true
+ nonamedreturns:
+ report-error-in-defer: true
+ predeclared:
+ qualified-name: true
+ promlinter:
+ strict: true
+ revive:
+ enable-all-rules: true
+ rules:
+ - name: add-constant
+ disabled: true
+ - name: argument-limit
+ disabled: true
+ - name: banned-characters
+ disabled: true
+ - name: cognitive-complexity
+ disabled: true
+ - name: comment-spacings
+ disabled: true # TODO https://github.com/gofiber/fiber/issues/2816
+ - name: cyclomatic
+ disabled: true
+ - name: early-return
+ severity: warning
+ disabled: true
+ - name: exported
+ disabled: true
+ - name: file-header
+ disabled: true
+ - name: function-result-limit
+ disabled: true
+ - name: function-length
+ disabled: true
+ - name: line-length-limit
+ disabled: true
+ - name: max-public-structs
+ disabled: true
+ - name: modifies-parameter
+ disabled: true
+ - name: nested-structs
+ disabled: true
+ - name: package-comments
+ disabled: true
+ - name: unchecked-type-assertion
+ disabled: true # TODO https://github.com/gofiber/fiber/issues/2816
+ - name: unhandled-error
+ disabled: true
+ - name: use-any
+ disabled: true
+ tagliatelle:
+ case:
+ rules:
+ json: snake
+ wrapcheck:
+ ignore-package-globs:
+ - github.com/gofiber/fiber/*
+ - github.com/valyala/fasthttp
+ exclusions:
+ paths:
+ - internal
+
+formatters:
+ enable:
+ - gofumpt
+ - goimports
+ settings:
+ gofumpt:
+ module-path: github.com/gofiber/template
+ extra-rules: true
diff --git a/README.md b/README.md
index f7bbaff..462c253 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ sidebar_position: 1
-
+
@@ -35,10 +35,10 @@ This package provides universal methods to use multiple template engines with th
- [slim](./slim/README.md)
### Installation
-> Go version `1.17` or higher is required.
+Go version support: We only support the latest two versions of Go. Visit https://go.dev/doc/devel/release for more information.
```
-go get -u github.com/gofiber/fiber/v2
+go get -u github.com/gofiber/fiber/v3
go get -u github.com/gofiber/template/any_template_engine/vX
```
@@ -49,15 +49,15 @@ package main
import (
"log"
- "github.com/gofiber/fiber/v2"
+ "github.com/gofiber/fiber/v3"
// To use a specific template engine, import as shown below:
- // "github.com/gofiber/template/pug"
- // "github.com/gofiber/template/mustache"
+ // "github.com/gofiber/template/pug/v3"
+ // "github.com/gofiber/template/mustache/v3"
// etc..
// In this example we use the html template engine
- "github.com/gofiber/template/html/v2"
+ "github.com/gofiber/template/html/v3"
)
func main() {
@@ -93,14 +93,14 @@ func main() {
// To render a template, you can call the ctx.Render function
// Render(tmpl string, values interface{}, layout ...string)
- app.Get("/", func(c *fiber.Ctx) error {
+ app.Get("/", func(c fiber.Ctx) error {
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
})
})
// Render with layout example
- app.Get("/layout", func(c *fiber.Ctx) error {
+ app.Get("/layout", func(c fiber.Ctx) error {
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
}, "layouts/main")
@@ -138,8 +138,8 @@ package main
import (
"log"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/html"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/template/html/v3"
"github.com/markbates/pkger"
)
@@ -163,8 +163,8 @@ package main
import (
"log"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/html"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/template/html/v3"
"github.com/gobuffalo/packr/v2"
)
@@ -188,8 +188,8 @@ package main
import (
"log"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/html"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/template/html/v3"
"github.com/GeertJohan/go.rice"
)
@@ -214,8 +214,8 @@ package main
import (
"log"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/html"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/template/html/v3"
// your generated package
"github.com///static"
)
diff --git a/ace/README.md b/ace/README.md
index 8303241..9c0d07c 100644
--- a/ace/README.md
+++ b/ace/README.md
@@ -9,7 +9,15 @@ title: Ace
Ace is a template engine create by [yossi](https://github.com/yosssi/ace), to see the original syntax documentation please [click here](https://github.com/yosssi/ace/blob/master/documentation/syntax.md)
-### Basic Example
+## Installation
+
+Go version support: We only support the latest two versions of Go. Visit https://go.dev/doc/devel/release for more information.
+
+```
+go get github.com/gofiber/template/ace/v3
+```
+
+## Basic Example
_**./views/index.ace**_
```html
@@ -43,8 +51,8 @@ package main
import (
"log"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/ace/v2"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/template/ace/v3"
)
func main() {
@@ -60,14 +68,14 @@ func main() {
Views: engine,
})
- app.Get("/", func(c *fiber.Ctx) error {
+ app.Get("/", func(c fiber.Ctx) error {
// Render index
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
})
})
- app.Get("/layout", func(c *fiber.Ctx) error {
+ app.Get("/layout", func(c fiber.Ctx) error {
// Render index within layouts/main
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
diff --git a/ace/ace.go b/ace/ace.go
index 3771f7d..c54aedc 100644
--- a/ace/ace.go
+++ b/ace/ace.go
@@ -10,7 +10,7 @@ import (
"path/filepath"
"strings"
- core "github.com/gofiber/template"
+ core "github.com/gofiber/template/v2"
"github.com/gofiber/utils"
"github.com/yosssi/ace"
)
diff --git a/ace/go.mod b/ace/go.mod
index c3764a8..a2651e3 100644
--- a/ace/go.mod
+++ b/ace/go.mod
@@ -1,11 +1,11 @@
-module github.com/gofiber/template/ace/v2
+module github.com/gofiber/template/ace/v3
-go 1.17
+go 1.25
require github.com/yosssi/ace v0.0.5
require (
- github.com/gofiber/template v1.8.3
+ github.com/gofiber/template/v2 v2.0.0
github.com/gofiber/utils v1.1.0
github.com/stretchr/testify v1.11.1
)
@@ -16,4 +16,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)
-replace github.com/gofiber/template => ../.
+replace github.com/gofiber/template/v2 => ../.
diff --git a/ace/go.sum b/ace/go.sum
index 882cf1b..1fb2e6f 100644
--- a/ace/go.sum
+++ b/ace/go.sum
@@ -1,23 +1,14 @@
-github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
-github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
-github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
-github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
-github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/yosssi/ace v0.0.5 h1:tUkIP/BLdKqrlrPwcmH0shwEEhTRHoGnc1wFIWmaBUA=
github.com/yosssi/ace v0.0.5/go.mod h1:ALfIzm2vT7t5ZE7uoIZqF3TQ7SAOyupFZnkrF5id+K0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/amber/README.md b/amber/README.md
index fc2b579..8eb0c24 100644
--- a/amber/README.md
+++ b/amber/README.md
@@ -9,7 +9,15 @@ title: Amber
Amber is a template engine create by [eknkc](https://github.com/eknkc/amber), to see the original syntax documentation please [click here](https://github.com/eknkc/amber#tags)
-### Basic Example
+## Installation
+
+Go version support: We only support the latest two versions of Go. Visit https://go.dev/doc/devel/release for more information.
+
+```
+go get github.com/gofiber/template/amber/v3
+```
+
+## Basic Example
_**./views/index.amber**_
```html
@@ -43,8 +51,8 @@ package main
import (
"log"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/amber/v2"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/template/amber/v3"
)
func main() {
@@ -60,14 +68,14 @@ func main() {
Views: engine,
})
- app.Get("/", func(c *fiber.Ctx) error {
+ app.Get("/", func(c fiber.Ctx) error {
// Render index
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
})
})
- app.Get("/layout", func(c *fiber.Ctx) error {
+ app.Get("/layout", func(c fiber.Ctx) error {
// Render index within layouts/main
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
diff --git a/amber/amber.go b/amber/amber.go
index 220b52d..dd6d893 100644
--- a/amber/amber.go
+++ b/amber/amber.go
@@ -11,7 +11,7 @@ import (
"strings"
"github.com/eknkc/amber"
- core "github.com/gofiber/template"
+ core "github.com/gofiber/template/v2"
"github.com/gofiber/utils"
)
diff --git a/amber/go.mod b/amber/go.mod
index 11b4379..f9b4222 100644
--- a/amber/go.mod
+++ b/amber/go.mod
@@ -1,10 +1,10 @@
-module github.com/gofiber/template/amber/v2
+module github.com/gofiber/template/amber/v3
-go 1.20
+go 1.25
require (
github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385
- github.com/gofiber/template v1.8.3
+ github.com/gofiber/template/v2 v2.0.0
github.com/gofiber/utils v1.1.0
github.com/stretchr/testify v1.11.1
)
@@ -15,4 +15,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)
-replace github.com/gofiber/template => ../.
+replace github.com/gofiber/template/v2 => ../.
diff --git a/django/README.md b/django/README.md
index 889e1a6..476fa69 100644
--- a/django/README.md
+++ b/django/README.md
@@ -9,7 +9,15 @@ title: Django
Django is a template engine create by [flosch](https://github.com/flosch/pongo2), to see the original syntax documentation please [click here](https://docs.djangoproject.com/en/dev/topics/templates/)
-### Basic Example
+## Installation
+
+Go version support: We only support the latest two versions of Go. Visit https://go.dev/doc/devel/release for more information.
+
+```
+go get github.com/gofiber/template/django/v4
+```
+
+## Basic Example
_**./views/index.django**_
```html
@@ -49,8 +57,8 @@ package main
import (
"log"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/django/v3"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/template/django/v4"
)
func main() {
@@ -66,14 +74,14 @@ func main() {
Views: engine,
})
- app.Get("/", func(c *fiber.Ctx) error {
+ app.Get("/", func(c fiber.Ctx) error {
// Render index
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
})
})
- app.Get("/layout", func(c *fiber.Ctx) error {
+ app.Get("/layout", func(c fiber.Ctx) error {
// Render index within layouts/main
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
@@ -105,8 +113,8 @@ import (
"embed"
"net/http"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/django/v3"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/template/django/v4"
)
//go:embed views
@@ -121,7 +129,7 @@ func main() {
Views: engine,
})
- app.Get("/", func(c *fiber.Ctx) error {
+ app.Get("/", func(c fiber.Ctx) error {
// Render descendant
return c.Render("descendant", fiber.Map{
"greeting": "World",
diff --git a/django/django.go b/django/django.go
index 77125df..02658a7 100644
--- a/django/django.go
+++ b/django/django.go
@@ -7,12 +7,11 @@ import (
"net/http"
"os"
"path/filepath"
+ "reflect"
"strings"
- "github.com/gofiber/fiber/v2"
-
"github.com/flosch/pongo2/v6"
- core "github.com/gofiber/template"
+ core "github.com/gofiber/template/v2"
"github.com/gofiber/utils"
)
@@ -154,38 +153,52 @@ func (e *Engine) Load() error {
// It supports the following types:
// - pongo2.Context
// - map[string]interface{}
-// - fiber.Map
-//
// It returns nil if the binding is not one of the supported types.
func getPongoBinding(binding interface{}) pongo2.Context {
if binding == nil {
return nil
}
- var bind pongo2.Context
switch binds := binding.(type) {
case pongo2.Context:
- bind = binds
+ return sanitizePongoContext(binds)
case map[string]interface{}:
- bind = binds
- case fiber.Map:
- bind = make(pongo2.Context)
- for key, value := range binds {
- // only add valid keys
- if isValidKey(key) {
- bind[key] = value
- }
+ return sanitizePongoContext(binds)
+ }
+
+ value := reflect.ValueOf(binding)
+ if value.Kind() != reflect.Map || value.IsNil() {
+ return nil
+ }
+
+ if value.Type().Key().Kind() != reflect.String {
+ return nil
+ }
+
+ bind := make(pongo2.Context, value.Len())
+ for _, key := range value.MapKeys() {
+ strKey := key.String()
+ if !isValidKey(strKey) {
+ continue
}
- return bind
+ bind[strKey] = value.MapIndex(key).Interface()
+ }
+
+ return bind
+}
+
+func sanitizePongoContext(data map[string]interface{}) pongo2.Context {
+ if len(data) == 0 {
+ return make(pongo2.Context)
}
- // Remove invalid keys
- for key := range bind {
+ bind := make(pongo2.Context, len(data))
+ for key, value := range data {
if !isValidKey(key) {
- delete(bind, key)
+ continue
}
+ bind[key] = value
}
-
return bind
}
diff --git a/django/django_test.go b/django/django_test.go
index 79c5d01..99070af 100644
--- a/django/django_test.go
+++ b/django/django_test.go
@@ -13,11 +13,12 @@ import (
"unicode"
"github.com/flosch/pongo2/v6"
- "github.com/gofiber/fiber/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
+type customMap map[string]interface{}
+
const (
admin = "admin"
)
@@ -116,10 +117,10 @@ func Test_GetPongoBinding(t *testing.T) {
result = getPongoBinding(mapBinding)
assert.Equal(t, pongo2.Context(mapBinding), result, "Expected the same context")
- // Test with fiber.Map
- fiberMap := fiber.Map{"key3": "value3"}
- result = getPongoBinding(fiberMap)
- assert.Equal(t, pongo2.Context(fiberMap), result, "Expected the same context")
+ // Test with custom map type (fiber.Map compatible)
+ custom := customMap{"key3": "value3"}
+ result = getPongoBinding(custom)
+ assert.Equal(t, pongo2.Context{"key3": "value3"}, result, "Expected the same context")
// Test with unsupported type
result = getPongoBinding("unsupported")
diff --git a/django/go.mod b/django/go.mod
index 3530dd5..cd76e6b 100644
--- a/django/go.mod
+++ b/django/go.mod
@@ -1,30 +1,18 @@
-module github.com/gofiber/template/django/v3
+module github.com/gofiber/template/django/v4
-go 1.20
+go 1.25
require (
github.com/flosch/pongo2/v6 v6.0.0
- github.com/gofiber/fiber/v2 v2.52.9
- github.com/gofiber/template v1.8.3
+ github.com/gofiber/template/v2 v2.0.0
github.com/gofiber/utils v1.1.0
github.com/stretchr/testify v1.11.1
)
require (
- github.com/andybalholm/brotli v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
- github.com/google/uuid v1.6.0 // indirect
- github.com/klauspost/compress v1.17.9 // indirect
- github.com/mattn/go-colorable v0.1.13 // indirect
- github.com/mattn/go-isatty v0.0.20 // indirect
- github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
- github.com/rivo/uniseg v0.2.0 // indirect
- github.com/valyala/bytebufferpool v1.0.0 // indirect
- github.com/valyala/fasthttp v1.51.0 // indirect
- github.com/valyala/tcplisten v1.0.0 // indirect
- golang.org/x/sys v0.28.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
-replace github.com/gofiber/template => ../.
+replace github.com/gofiber/template/v2 => ../.
diff --git a/django/go.sum b/django/go.sum
index e30431a..9d6f39f 100644
--- a/django/go.sum
+++ b/django/go.sum
@@ -1,43 +1,19 @@
-github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
-github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/flosch/pongo2/v6 v6.0.0 h1:lsGru8IAzHgIAw6H2m4PCyleO58I40ow6apih0WprMU=
github.com/flosch/pongo2/v6 v6.0.0/go.mod h1:CuDpFm47R0uGGE7z13/tTlt1Y6zdxvr2RLT5LJhsHEU=
-github.com/gofiber/fiber/v2 v2.52.9 h1:YjKl5DOiyP3j0mO61u3NTmK7or8GzzWzCFzkboyP5cw=
-github.com/gofiber/fiber/v2 v2.52.9/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
-github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
-github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
-github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
-github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
+github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
-github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
-github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
-github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
-github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
-github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
-github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
-github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
+github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
-github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
-github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
-github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
-github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
-github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
-github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
-github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
-golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
-golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
+gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/go.mod b/go.mod
index 6a7ace8..3e6d412 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,3 @@
-module github.com/gofiber/template
+module github.com/gofiber/template/v2
-go 1.20
+go 1.25
diff --git a/handlebars/README.md b/handlebars/README.md
index 6cb7ff2..f01418d 100644
--- a/handlebars/README.md
+++ b/handlebars/README.md
@@ -9,7 +9,15 @@ title: Handlebars
Handlebars is a template engine create by [aymerick](https://github.com/aymerick/raymond), to see the original syntax documentation please [click here](https://github.com/aymerick/raymond#table-of-contents)
-### Basic Example
+## Installation
+
+Go version support: We only support the latest two versions of Go. Visit https://go.dev/doc/devel/release for more information.
+
+```
+go get github.com/gofiber/template/handlebars/v3
+```
+
+## Basic Example
_**./views/index.hbs**_
```html
@@ -49,8 +57,8 @@ package main
import (
"log"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/handlebars/v2"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/template/handlebars/v3"
)
func main() {
@@ -66,14 +74,14 @@ func main() {
Views: engine,
})
- app.Get("/", func(c *fiber.Ctx) error {
+ app.Get("/", func(c fiber.Ctx) error {
// Render index
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
})
})
- app.Get("/layout", func(c *fiber.Ctx) error {
+ app.Get("/layout", func(c fiber.Ctx) error {
// Render index within layouts/main
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
diff --git a/handlebars/go.mod b/handlebars/go.mod
index e4cd796..9411922 100644
--- a/handlebars/go.mod
+++ b/handlebars/go.mod
@@ -1,31 +1,20 @@
-module github.com/gofiber/template/handlebars/v2
+module github.com/gofiber/template/handlebars/v3
-go 1.20
+go 1.25
require (
- github.com/gofiber/fiber/v2 v2.52.9
- github.com/gofiber/template v1.8.3
+ github.com/gofiber/template/v2 v2.0.0
github.com/gofiber/utils v1.1.0
github.com/mailgun/raymond/v2 v2.0.48
github.com/stretchr/testify v1.11.1
)
require (
- github.com/andybalholm/brotli v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
- github.com/google/uuid v1.6.0 // indirect
- github.com/klauspost/compress v1.17.9 // indirect
- github.com/mattn/go-colorable v0.1.13 // indirect
- github.com/mattn/go-isatty v0.0.20 // indirect
- github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
- github.com/rivo/uniseg v0.2.0 // indirect
- github.com/sirupsen/logrus v1.8.1 // indirect
- github.com/valyala/bytebufferpool v1.0.0 // indirect
- github.com/valyala/fasthttp v1.51.0 // indirect
- github.com/valyala/tcplisten v1.0.0 // indirect
- golang.org/x/sys v0.28.0 // indirect
+ github.com/sirupsen/logrus v1.9.3 // indirect
+ golang.org/x/sys v0.37.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
-replace github.com/gofiber/template => ../.
+replace github.com/gofiber/template/v2 => ../.
diff --git a/handlebars/go.sum b/handlebars/go.sum
index 61333db..076f4f6 100644
--- a/handlebars/go.sum
+++ b/handlebars/go.sum
@@ -1,47 +1,24 @@
-github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
-github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/gofiber/fiber/v2 v2.52.9 h1:YjKl5DOiyP3j0mO61u3NTmK7or8GzzWzCFzkboyP5cw=
-github.com/gofiber/fiber/v2 v2.52.9/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
-github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
-github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
-github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
-github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/mailgun/raymond/v2 v2.0.48 h1:5dmlB680ZkFG2RN/0lvTAghrSxIESeu9/2aeDqACtjw=
github.com/mailgun/raymond/v2 v2.0.48/go.mod h1:lsgvL50kgt1ylcFJYZiULi5fjPBkkhNfj4KA0W54Z18=
-github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
-github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
-github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
-github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
-github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
-github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
-github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
-github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
-github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
+github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
+github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
-github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
-github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
-github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
-github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
-github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
-github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
-golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
+golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
diff --git a/handlebars/handlebars.go b/handlebars/handlebars.go
index fb64f32..1ba69ff 100644
--- a/handlebars/handlebars.go
+++ b/handlebars/handlebars.go
@@ -10,9 +10,7 @@ import (
"strings"
"sync"
- "github.com/gofiber/fiber/v2"
-
- core "github.com/gofiber/template"
+ core "github.com/gofiber/template/v2"
"github.com/gofiber/utils"
"github.com/mailgun/raymond/v2"
)
@@ -157,15 +155,7 @@ func (e *Engine) Render(out io.Writer, name string, binding interface{}, layout
if lay == nil {
return fmt.Errorf("render: LayoutName %s does not exist", layout[0])
}
- var bind map[string]interface{}
- switch binds := binding.(type) {
- case fiber.Map:
- bind = binds
- case map[string]interface{}:
- bind = binds
- default:
- bind = make(map[string]interface{}, 1)
- }
+ bind := core.AcquireViewContext(binding)
bind[e.LayoutName] = raymond.SafeString(parsed)
parsed, err := lay.Exec(bind)
if err != nil {
diff --git a/handlebars/handlebars_test.go b/handlebars/handlebars_test.go
index ae830c1..4832d6a 100644
--- a/handlebars/handlebars_test.go
+++ b/handlebars/handlebars_test.go
@@ -9,10 +9,10 @@ import (
"testing"
"github.com/stretchr/testify/require"
-
- "github.com/gofiber/fiber/v2"
)
+type customMap map[string]interface{}
+
func trim(str string) string {
trimmed := strings.TrimSpace(regexp.MustCompile(`\s+`).ReplaceAllString(str, " "))
trimmed = strings.ReplaceAll(trimmed, " <", "<")
@@ -27,7 +27,7 @@ func Test_Render(t *testing.T) {
// Partials
var buf bytes.Buffer
- err := engine.Render(&buf, "index", fiber.Map{
+ err := engine.Render(&buf, "index", customMap{
"Title": "Hello, World!",
})
require.NoError(t, err)
@@ -38,7 +38,7 @@ func Test_Render(t *testing.T) {
// Single
buf.Reset()
- err = engine.Render(&buf, "errors/404", fiber.Map{
+ err = engine.Render(&buf, "errors/404", customMap{
"Title": "Hello, World!",
})
require.NoError(t, err)
@@ -54,7 +54,7 @@ func Test_Layout(t *testing.T) {
require.NoError(t, engine.Load())
var buf bytes.Buffer
- err := engine.Render(&buf, "index", fiber.Map{
+ err := engine.Render(&buf, "index", customMap{
"Title": "Hello, World!",
}, "layouts/main")
require.NoError(t, err)
@@ -70,7 +70,7 @@ func Test_Empty_Layout(t *testing.T) {
require.NoError(t, engine.Load())
var buf bytes.Buffer
- err := engine.Render(&buf, "index", fiber.Map{
+ err := engine.Render(&buf, "index", customMap{
"Title": "Hello, World!",
}, "")
require.NoError(t, err)
@@ -87,7 +87,7 @@ func Test_FileSystem(t *testing.T) {
require.NoError(t, engine.Load())
var buf bytes.Buffer
- err := engine.Render(&buf, "index", fiber.Map{
+ err := engine.Render(&buf, "index", customMap{
"Title": "Hello, World!",
}, "layouts/main")
require.NoError(t, err)
diff --git a/html/README.md b/html/README.md
index 1711fbf..bdd6044 100644
--- a/html/README.md
+++ b/html/README.md
@@ -9,13 +9,21 @@ title: HTML
HTML is the official Go template engine [html/template](https://golang.org/pkg/html/template/), to see the original syntax documentation please [click here](TEMPLATES_CHEATSHEET.md)
+## Installation
+
+Go version support: We only support the latest two versions of Go. Visit https://go.dev/doc/devel/release for more information.
+
+```
+go get github.com/gofiber/template/html/v3
+```
+
**Info:**
All templates within the specified view directory are analyzed and compiled at the beginning to increase the performance when using them.
Thus it should be noted that no `definition` with the same name should exist, otherwise they will overwrite each other.
For templating the `{{embed}}` tag should be used
-### Basic Example
+## Basic Example
_**./views/index.html**_
@@ -60,8 +68,8 @@ package main
import (
"log"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/html/v2"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/template/html/v3"
)
func main() {
@@ -77,21 +85,21 @@ func main() {
Views: engine,
})
- app.Get("/", func(c *fiber.Ctx) error {
+ app.Get("/", func(c fiber.Ctx) error {
// Render index
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
})
})
- app.Get("/layout", func(c *fiber.Ctx) error {
+ app.Get("/layout", func(c fiber.Ctx) error {
// Render index within layouts/main
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
}, "layouts/main")
})
- app.Get("/layouts-nested", func(c *fiber.Ctx) error {
+ app.Get("/layouts-nested", func(c fiber.Ctx) error {
// Render index within layouts/nested/main within layouts/nested/base
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
@@ -113,8 +121,8 @@ import (
"net/http"
"embed"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/html/v2"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/template/html/v3"
)
//go:embed views/*
@@ -129,7 +137,7 @@ func main() {
})
- app.Get("/", func(c *fiber.Ctx) error {
+ app.Get("/", func(c fiber.Ctx) error {
// Render index - start with views directory
return c.Render("views/index", fiber.Map{
"Title": "Hello, World!",
@@ -163,8 +171,8 @@ import (
"log"
"net/http"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/html/v2"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/template/html/v3"
)
//go:embed views/*
@@ -182,7 +190,7 @@ func main() {
// Pass the engine to the Views
app := fiber.New(fiber.Config{Views: engine})
- app.Get("/", func(c *fiber.Ctx) error {
+ app.Get("/", func(c fiber.Ctx) error {
// Render index
return c.Render("views/index", fiber.Map{
"Title": "Hello, World!",
diff --git a/html/go.mod b/html/go.mod
index 7b72307..67f0297 100644
--- a/html/go.mod
+++ b/html/go.mod
@@ -1,9 +1,9 @@
-module github.com/gofiber/template/html/v2
+module github.com/gofiber/template/html/v3
-go 1.20
+go 1.25
require (
- github.com/gofiber/template v1.8.3
+ github.com/gofiber/template/v2 v2.0.0
github.com/gofiber/utils v1.1.0
github.com/stretchr/testify v1.11.1
)
@@ -14,4 +14,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)
-replace github.com/gofiber/template => ../.
+replace github.com/gofiber/template/v2 => ../.
diff --git a/html/html.go b/html/html.go
index 4c1c4c2..18d7190 100644
--- a/html/html.go
+++ b/html/html.go
@@ -10,7 +10,7 @@ import (
"path/filepath"
"strings"
- core "github.com/gofiber/template"
+ core "github.com/gofiber/template/v2"
"github.com/gofiber/utils"
)
diff --git a/jet/README.md b/jet/README.md
index 8a9c85b..72f1059 100644
--- a/jet/README.md
+++ b/jet/README.md
@@ -9,7 +9,15 @@ title: Jet
Jet is a template engine create by [cloudykit](https://github.com/CloudyKit/jet), to see the original syntax documentation please [click here](https://github.com/CloudyKit/jet/wiki/3.-Jet-template-syntax)
-### Basic Example
+## Installation
+
+Go version support: We only support the latest two versions of Go. Visit https://go.dev/doc/devel/release for more information.
+
+```
+go get github.com/gofiber/template/jet/v4
+```
+
+## Basic Example
_**./views/index.jet**_
```html
@@ -49,8 +57,8 @@ package main
import (
"log"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/jet/v2"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/template/jet/v3"
)
func main() {
@@ -66,14 +74,14 @@ func main() {
Views: engine,
})
- app.Get("/", func(c *fiber.Ctx) error {
+ app.Get("/", func(c fiber.Ctx) error {
// Render index
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
})
})
- app.Get("/layout", func(c *fiber.Ctx) error {
+ app.Get("/layout", func(c fiber.Ctx) error {
// Render index within layouts/main
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
diff --git a/jet/go.mod b/jet/go.mod
index 07035bf..729a408 100644
--- a/jet/go.mod
+++ b/jet/go.mod
@@ -1,31 +1,19 @@
-module github.com/gofiber/template/jet/v2
+module github.com/gofiber/template/jet/v3
-go 1.20
+go 1.25
require (
github.com/CloudyKit/jet/v6 v6.3.1
- github.com/gofiber/fiber/v2 v2.52.9
- github.com/gofiber/template v1.8.3
+ github.com/gofiber/template/v2 v2.0.0
github.com/gofiber/utils v1.1.0
github.com/stretchr/testify v1.11.1
)
require (
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect
- github.com/andybalholm/brotli v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
- github.com/google/uuid v1.6.0 // indirect
- github.com/klauspost/compress v1.17.9 // indirect
- github.com/mattn/go-colorable v0.1.13 // indirect
- github.com/mattn/go-isatty v0.0.20 // indirect
- github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
- github.com/rivo/uniseg v0.2.0 // indirect
- github.com/valyala/bytebufferpool v1.0.0 // indirect
- github.com/valyala/fasthttp v1.51.0 // indirect
- github.com/valyala/tcplisten v1.0.0 // indirect
- golang.org/x/sys v0.28.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
-replace github.com/gofiber/template => ../.
+replace github.com/gofiber/template/v2 => ../.
diff --git a/jet/go.sum b/jet/go.sum
index d4384f9..162459f 100644
--- a/jet/go.sum
+++ b/jet/go.sum
@@ -2,41 +2,14 @@ github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 h1:sR+/8Yb4s
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno=
github.com/CloudyKit/jet/v6 v6.3.1 h1:6IAo5Cx21xrHVaR8zzXN5gJatKV/wO7Nf6bfCnCSbUw=
github.com/CloudyKit/jet/v6 v6.3.1/go.mod h1:lf8ksdNsxZt7/yH/3n4vJQWA9RUq4wpaHtArHhGVMOw=
-github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
-github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/gofiber/fiber/v2 v2.52.9 h1:YjKl5DOiyP3j0mO61u3NTmK7or8GzzWzCFzkboyP5cw=
-github.com/gofiber/fiber/v2 v2.52.9/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
-github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
-github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
-github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
-github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
-github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
-github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
-github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
-github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
-github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
-github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
-github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
-github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
-github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
-github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
-github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
-github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
-github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
-github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
-golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
-golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
diff --git a/jet/jet.go b/jet/jet.go
index edb3510..4642c38 100644
--- a/jet/jet.go
+++ b/jet/jet.go
@@ -9,11 +9,9 @@ import (
"path/filepath"
"strings"
- "github.com/gofiber/fiber/v2"
-
"github.com/CloudyKit/jet/v6"
"github.com/CloudyKit/jet/v6/loaders/httpfs"
- core "github.com/gofiber/template"
+ core "github.com/gofiber/template/v2"
"github.com/gofiber/utils"
)
@@ -192,23 +190,18 @@ func (e *Engine) Render(out io.Writer, name string, binding interface{}, layout
}
func jetVarMap(binding interface{}) jet.VarMap {
- var bind jet.VarMap
if binding == nil {
+ return nil
+ }
+
+ if bind, ok := binding.(jet.VarMap); ok {
return bind
}
- switch binds := binding.(type) {
- case map[string]interface{}:
- bind = make(jet.VarMap)
- for key, value := range binds {
- bind.Set(key, value)
- }
- case fiber.Map:
- bind = make(jet.VarMap)
- for key, value := range binds {
- bind.Set(key, value)
- }
- case jet.VarMap:
- bind = binds
+
+ data := core.AcquireViewContext(binding)
+ bind := make(jet.VarMap)
+ for key, value := range data {
+ bind.Set(key, value)
}
return bind
}
diff --git a/mustache/README.md b/mustache/README.md
index a8c7c86..3aeea55 100644
--- a/mustache/README.md
+++ b/mustache/README.md
@@ -9,7 +9,15 @@ title: Mustache
Mustache is a template engine created by [hoisie/cbroglie](https://github.com/cbroglie/mustache), to see the original syntax documentation please [click here](https://mustache.github.io/mustache.5.html)
-### Basic Example
+## Installation
+
+Go version support: We only support the latest two versions of Go. Visit https://go.dev/doc/devel/release for more information.
+
+```
+go get github.com/gofiber/template/mustache/v4
+```
+
+## Basic Example
_**./views/index.mustache**_
```html
@@ -49,8 +57,8 @@ package main
import (
"log"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/mustache/v2"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/template/mustache/v3"
)
func main() {
@@ -67,14 +75,14 @@ func main() {
Views: engine,
})
- app.Get("/", func(c *fiber.Ctx) error {
+ app.Get("/", func(c fiber.Ctx) error {
// Render index
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
})
})
- app.Get("/layout", func(c *fiber.Ctx) error {
+ app.Get("/layout", func(c fiber.Ctx) error {
// Render index within layouts/main
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
diff --git a/mustache/go.mod b/mustache/go.mod
index 384d6ed..64a207f 100644
--- a/mustache/go.mod
+++ b/mustache/go.mod
@@ -1,30 +1,19 @@
-module github.com/gofiber/template/mustache/v2
+module github.com/gofiber/template/mustache/v3
-go 1.20
+go 1.25
require (
github.com/cbroglie/mustache v1.4.0
- github.com/gofiber/fiber/v2 v2.52.9
- github.com/gofiber/template v1.8.3
+ github.com/gofiber/template/v2 v2.0.0
github.com/gofiber/utils v1.1.0
github.com/stretchr/testify v1.11.1
github.com/valyala/bytebufferpool v1.0.0
)
require (
- github.com/andybalholm/brotli v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
- github.com/google/uuid v1.6.0 // indirect
- github.com/klauspost/compress v1.17.9 // indirect
- github.com/mattn/go-colorable v0.1.13 // indirect
- github.com/mattn/go-isatty v0.0.20 // indirect
- github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
- github.com/rivo/uniseg v0.2.0 // indirect
- github.com/valyala/fasthttp v1.51.0 // indirect
- github.com/valyala/tcplisten v1.0.0 // indirect
- golang.org/x/sys v0.28.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
-replace github.com/gofiber/template => ../.
+replace github.com/gofiber/template/v2 => ../.
diff --git a/mustache/go.sum b/mustache/go.sum
index 46480ce..be3c93a 100644
--- a/mustache/go.sum
+++ b/mustache/go.sum
@@ -1,40 +1,15 @@
-github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
-github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/cbroglie/mustache v1.4.0 h1:Azg0dVhxTml5me+7PsZ7WPrQq1Gkf3WApcHMjMprYoU=
github.com/cbroglie/mustache v1.4.0/go.mod h1:SS1FTIghy0sjse4DUVGV1k/40B1qE1XkD9DtDsHo9iM=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/gofiber/fiber/v2 v2.52.9 h1:YjKl5DOiyP3j0mO61u3NTmK7or8GzzWzCFzkboyP5cw=
-github.com/gofiber/fiber/v2 v2.52.9/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM=
github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0=
-github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
-github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
-github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
-github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
-github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
-github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
-github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
-github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
-github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
-github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
-github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
-github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
-github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
-github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
-github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
-github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
-golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
-golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
-golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
diff --git a/mustache/mustache.go b/mustache/mustache.go
index a2c15ff..9467dc4 100644
--- a/mustache/mustache.go
+++ b/mustache/mustache.go
@@ -9,10 +9,8 @@ import (
"path/filepath"
"strings"
- "github.com/gofiber/fiber/v2"
-
"github.com/cbroglie/mustache"
- core "github.com/gofiber/template"
+ core "github.com/gofiber/template/v2"
"github.com/gofiber/utils"
"github.com/valyala/bytebufferpool"
)
@@ -173,17 +171,7 @@ func (e *Engine) Render(out io.Writer, name string, binding interface{}, layout
return err
}
- var bind map[string]interface{}
-
- switch binds := binding.(type) {
- case fiber.Map:
- bind = binds
- case map[string]interface{}:
- bind = binds
- default:
- bind = make(map[string]interface{}, 1)
- }
-
+ bind := core.AcquireViewContext(binding)
bind[e.LayoutName] = buf.String()
lay := e.Templates[layout[0]]
if lay == nil {
diff --git a/mustache/mustache_test.go b/mustache/mustache_test.go
index 6605600..be45c2f 100644
--- a/mustache/mustache_test.go
+++ b/mustache/mustache_test.go
@@ -9,10 +9,10 @@ import (
"testing"
"github.com/stretchr/testify/require"
-
- "github.com/gofiber/fiber/v2"
)
+type customMap map[string]interface{}
+
func trim(str string) string {
trimmed := strings.TrimSpace(regexp.MustCompile(`\s+`).ReplaceAllString(str, " "))
trimmed = strings.ReplaceAll(trimmed, " <", "<")
@@ -27,7 +27,7 @@ func Test_Render(t *testing.T) {
// Partials
var buf bytes.Buffer
- err := engine.Render(&buf, "index", fiber.Map{
+ err := engine.Render(&buf, "index", customMap{
"Title": "Hello, World!",
})
require.NoError(t, err)
@@ -38,7 +38,7 @@ func Test_Render(t *testing.T) {
// Single
buf.Reset()
- err = engine.Render(&buf, "errors/404", fiber.Map{
+ err = engine.Render(&buf, "errors/404", customMap{
"Title": "Hello, World!",
})
require.NoError(t, err)
@@ -54,7 +54,7 @@ func Test_Layout(t *testing.T) {
require.NoError(t, engine.Load())
var buf bytes.Buffer
- err := engine.Render(&buf, "index", fiber.Map{
+ err := engine.Render(&buf, "index", customMap{
"Title": "Hello, World!",
}, "layouts/main")
require.NoError(t, err)
@@ -70,7 +70,7 @@ func Test_Empty_Layout(t *testing.T) {
require.NoError(t, engine.Load())
var buf bytes.Buffer
- err := engine.Render(&buf, "index", fiber.Map{
+ err := engine.Render(&buf, "index", customMap{
"Title": "Hello, World!",
}, "")
require.NoError(t, err)
@@ -86,7 +86,7 @@ func Test_FileSystem(t *testing.T) {
require.NoError(t, engine.Load())
var buf bytes.Buffer
- err := engine.Render(&buf, "index", fiber.Map{
+ err := engine.Render(&buf, "index", customMap{
"Title": "Hello, World!",
}, "layouts/main")
require.NoError(t, err)
diff --git a/pug/README.md b/pug/README.md
index 8f2c40a..d434090 100644
--- a/pug/README.md
+++ b/pug/README.md
@@ -9,7 +9,15 @@ title: Pug
Pug is a template engine create by [joker](https://github.com/Joker/jade), to see the original syntax documentation please [click here](https://pugjs.org/language/tags.html)
-### Basic Example
+## Installation
+
+Go version support: We only support the latest two versions of Go. Visit https://go.dev/doc/devel/release for more information.
+
+```
+go get github.com/gofiber/template/pug/v3
+```
+
+## Basic Example
_**./views/index.pug**_
```html
@@ -44,8 +52,8 @@ package main
import (
"log"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/pug/v2"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/template/pug/v3"
// "net/http" // embedded system
)
@@ -63,14 +71,14 @@ func main() {
Views: engine,
})
- app.Get("/", func(c *fiber.Ctx) error {
+ app.Get("/", func(c fiber.Ctx) error {
// Render index
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
})
})
- app.Get("/layout", func(c *fiber.Ctx) error {
+ app.Get("/layout", func(c fiber.Ctx) error {
// Render index within layouts/main
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
diff --git a/pug/go.mod b/pug/go.mod
index 29eeba8..93f4bb1 100644
--- a/pug/go.mod
+++ b/pug/go.mod
@@ -1,11 +1,11 @@
-module github.com/gofiber/template/pug/v2
+module github.com/gofiber/template/pug/v3
-go 1.20
+go 1.25
require (
github.com/Joker/hpp v1.0.0
github.com/Joker/jade v1.1.3
- github.com/gofiber/template v1.8.3
+ github.com/gofiber/template/v2 v2.0.0
github.com/gofiber/utils v1.1.0
github.com/stretchr/testify v1.11.1
)
@@ -13,8 +13,8 @@ require (
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
- golang.org/x/net v0.33.0 // indirect
+ golang.org/x/net v0.46.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
-replace github.com/gofiber/template => ../.
+replace github.com/gofiber/template/v2 => ../.
diff --git a/pug/go.sum b/pug/go.sum
index af7a5db..694177c 100644
--- a/pug/go.sum
+++ b/pug/go.sum
@@ -19,8 +19,8 @@ golang.org/x/net v0.0.0-20190327091125-710a502c58a2/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
-golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
-golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
+golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4=
+golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
diff --git a/pug/pug.go b/pug/pug.go
index d30068f..8af198f 100644
--- a/pug/pug.go
+++ b/pug/pug.go
@@ -12,7 +12,7 @@ import (
"github.com/Joker/hpp"
"github.com/Joker/jade"
- core "github.com/gofiber/template"
+ core "github.com/gofiber/template/v2"
"github.com/gofiber/utils"
)
diff --git a/slim/README.md b/slim/README.md
index b4c4ad5..eb2e035 100644
--- a/slim/README.md
+++ b/slim/README.md
@@ -9,7 +9,15 @@ title: Slim
Slim is a template engine created by [mattn](https://github.com/mattn/go-slim), to see the original syntax documentation please [click here](https://rubydoc.info/gems/slim/frames)
-### Basic Example
+## Installation
+
+Go version support: We only support the latest two versions of Go. Visit https://go.dev/doc/devel/release for more information.
+
+```
+go get github.com/gofiber/template/slim/v3
+```
+
+## Basic Example
_**./views/index.slim**_
```html
@@ -44,8 +52,8 @@ package main
import (
"log"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/template/slim/v2"
+ "github.com/gofiber/fiber/v3"
+ "github.com/gofiber/template/slim/v3"
// "net/http" // embedded system
)
@@ -63,14 +71,14 @@ func main() {
Views: engine,
})
- app.Get("/", func(c *fiber.Ctx) error {
+ app.Get("/", func(c fiber.Ctx) error {
// Render index
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
})
})
- app.Get("/layout", func(c *fiber.Ctx) error {
+ app.Get("/layout", func(c fiber.Ctx) error {
// Render index within layouts/main
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
diff --git a/slim/go.mod b/slim/go.mod
index 544465e..d39b409 100644
--- a/slim/go.mod
+++ b/slim/go.mod
@@ -1,9 +1,9 @@
-module github.com/gofiber/template/slim/v2
+module github.com/gofiber/template/slim/v3
-go 1.20
+go 1.25
require (
- github.com/gofiber/template v1.8.3
+ github.com/gofiber/template/v2 v2.0.0
github.com/gofiber/utils v1.1.0
github.com/mattn/go-slim v0.0.4
github.com/stretchr/testify v1.11.1
@@ -16,4 +16,4 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
)
-replace github.com/gofiber/template => ../.
+replace github.com/gofiber/template/v2 => ../.
diff --git a/slim/slim.go b/slim/slim.go
index e10ab9b..ce04396 100644
--- a/slim/slim.go
+++ b/slim/slim.go
@@ -10,7 +10,7 @@ import (
"path/filepath"
"strings"
- core "github.com/gofiber/template"
+ core "github.com/gofiber/template/v2"
"github.com/gofiber/utils"
"github.com/mattn/go-slim"
"github.com/valyala/bytebufferpool"
diff --git a/template.go b/template.go
index ab443f6..feb8691 100644
--- a/template.go
+++ b/template.go
@@ -1,8 +1,10 @@
+// Package template provides shared rendering primitives for Fiber template engines.
package template
import (
"io"
"net/http"
+ "reflect"
"sync"
)
@@ -112,8 +114,8 @@ func (e *Engine) Reload(enabled bool) IEngineCore {
return e
}
-// Check if the engine should reload the templates before rendering
-// Explicit Mute Unlock vs defer offers better performance
+// PreRenderCheck determines if the engine should reload the templates before rendering.
+// Explicit mutex unlock vs defer offers better performance.
func (e *Engine) PreRenderCheck() bool {
e.Mutex.Lock()
@@ -127,3 +129,40 @@ func (e *Engine) PreRenderCheck() bool {
e.Mutex.Unlock()
return false
}
+
+// AcquireViewContext ensures the binding value is represented as a map[string]interface{}
+// so template engines can safely inject layout specific data while preserving the
+// original values. It supports native map[string]interface{} values as well as
+// user-defined map types (for example fiber.Map) with string keys.
+func AcquireViewContext(binding interface{}) map[string]interface{} {
+ if binds, ok := binding.(map[string]interface{}); ok {
+ return binds
+ }
+
+ if binding == nil {
+ return make(map[string]interface{})
+ }
+
+ val := reflect.ValueOf(binding)
+ if val.Kind() == reflect.Pointer {
+ if val.IsNil() {
+ return make(map[string]interface{})
+ }
+ val = val.Elem()
+ }
+
+ if val.Kind() != reflect.Map || val.IsNil() {
+ return make(map[string]interface{})
+ }
+
+ if val.Type().Key().Kind() != reflect.String {
+ return make(map[string]interface{})
+ }
+
+ result := make(map[string]interface{}, val.Len())
+ iter := val.MapRange()
+ for iter.Next() {
+ result[iter.Key().String()] = iter.Value().Interface()
+ }
+ return result
+}