Hi!
How to fix this problem?
Cannot use 'templateFSConvert' (type "text/template".Template) as the type "html/template".Template
package main
import (
"embed"
"github.com/gin-gonic/gin"
"log"
"text/template"
)
//go:embed assets/* templates/*
var f embed.FS
func main() {
app := gin.Default()
templateFSConvert := template.Must(template.New("").ParseFS(f, "templates/*.tmpl", "templates/inc/*.tmpl"))
app.SetHTMLTemplate(templateFSConvert)
app.Static("/files", "./static")
app.GET("/", hindex)
app.GET("/main", hmain)
app.GET("/weather/:reqType", hweather)
err := app.Run(":7001")
if err != nil {
log.Fatalln("Ошибка запуска сервера")
}
}
Comment From: ghost
File struct:
/templates/inc/.tmpl templates/.tmpl
Full error text:
.\main.go:19:22: cannot use templateFSConvert (variable of type *"text/template".Template) as type *"html/template".Template in argument to app.SetHTMLTemplate
Comment From: ghost
No help! fUf
Comment From: MansonLuo
hi, you should remove "text/template" at import statement, replace it with "http/template"