- With issues:
- Use the search tool before opening a new issue.
- Please provide source code and commit sha if you found a bug.
- Review existing issues and provide feedback or react to them.
Description
I have template directory with only one file:
But LoadHTMLGlob
found extra template without a name
How to reproduce
package main
import (
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
router.LoadHTMLGlob("templates/*")
}
Expectations
[GIN-debug] Loaded HTML Templates (1):
- index.tmpl
Actual result
[GIN-debug] Loaded HTML Templates (2):
-
- index.tmpl
Environment
- go version: 1.16.3
- gin version (or commit ref): I ran today
go get -u github.com/gin-gonic/gin
. Nowhere was it written which version was installed. - operating system: WIndows 10
Comment From: leungyauming
~I believe it should be some issues in matching template files, then the default template name set by templ := template.Must(template.New("").Delims(left, right).Funcs(engine.FuncMap).ParseGlob(pattern))
is used.~
Edit: The empty template without name is caused by template.New("")
.
Comment From: rushairer
Ha ha, so it is. It's hard for those who pursue perfection.
Comment From: ethrgeist
I can confirm the behavior and while only confusing, i think that there is a random empty entry in a list is weird behavior for such explicit language as Go, can this be fixed? :)