Description
Getting wrong template list in debug mode in output when running application. The statement in below line template.New("") creates an empty template that appear in list later on in debug message.
templ := template.Must(template.New("").Delims(left, right).Funcs(engine.FuncMap).ParseGlob(pattern))
output: [GIN-debug] Loaded HTML Templates (3): - - header.html - login.html
Expected: There should be two templates listed only. There should not be blank template in list.
- go version: v1.18
- gin version: v1.7.7
- operating system: MacOS v12.3
Comment From: pscheid92
I'm afraid we cannot get rid of the empty template. We need it to register custom delimiters before parsing the template files with ParseGlob(pattern)
. Unfortunately, there is no other way to do this with html/template
.
We could filter it out in the debug message, but I don't think this would be sensible. Filtering it out would IMHO be an utter lie and make people's life more complicated if the empty template should cause some problems.
If we would give the empty template a more descriptive name, it could clash with if a used one, couldn't it?
I think it isn't lovely, but it is the best thing we could do.
Comment From: ericbrown30
Now, I am getting correct count for template list in debug log. So, is it fixed?
Comment From: pscheid92
🤔 For me it is still the same.
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
- using env: export GIN_MODE=release
- using code: gin.SetMode(gin.ReleaseMode)
[GIN-debug] Loaded HTML Templates (2):
-
- base.gohtml
Comment From: colinshin
I got the same problem and can not find template
html/template: "admin/login.html" is undefined
E:/GOPATH/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:911 (0x155a8fb)
(*Context).Render: panic(err)
E:/GOPATH/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:920 (0x155a9cd)
(*Context).HTML: c.Render(code, instance)
E:/GolandProjects/qixing/controller/admin/index.go:45 (0x1858009)
LoginPage: c.HTML(http.StatusOK, "admin/login.html", gin.H{})
E:/GOPATH/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173 (0x1554dfc)
(*Context).Next: c.handlers[c.index](c)
E:/GOPATH/pkg/mod/github.com/gin-contrib/sessions@v0.0.3/sessions.go:52 (0x1576de4)
Sessions.func1: c.Next()
E:/GOPATH/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173 (0x1554dfc)
(*Context).Next: c.handlers[c.index](c)
E:/GOPATH/pkg/mod/github.com/gin-gonic/gin@v1.8.1/recovery.go:101 (0x1568197)
CustomRecoveryWithWriter.func1: c.Next()
E:/GOPATH/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173 (0x1554dfc)
(*Context).Next: c.handlers[c.index](c)
E:/GOPATH/pkg/mod/github.com/gin-gonic/gin@v1.8.1/logger.go:240 (0x1566b51)
LoggerWithConfig.func1: c.Next()
E:/GOPATH/pkg/mod/github.com/gin-gonic/gin@v1.8.1/context.go:173 (0x1554dfc)
(*Context).Next: c.handlers[c.index](c)
E:/GOPATH/pkg/mod/github.com/gin-gonic/gin@v1.8.1/gin.go:616 (0x1564793)
(*Engine).handleHTTPRequest: c.Next()
E:/GOPATH/pkg/mod/github.com/gin-gonic/gin@v1.8.1/gin.go:572 (0x1564264)
(*Engine).ServeHTTP: engine.handleHTTPRequest(c)
C:/Go/src/net/http/server.go:2947 (0x1258913)
serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
C:/Go/src/net/http/server.go:1991 (0x12524fb)
(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
C:/Go/src/runtime/asm_amd64.s:1594 (0xe5da00)
goexit: BYTE $0x90 // NOP
Comment From: infected-engineer
Hope you have already resolved it but it doesn't seem same problem and there's something wrong with path you provided for templates.