优化
This commit is contained in:
parent
00298c2058
commit
4676bfac93
|
@ -25,9 +25,7 @@ func SetupRouter() *gin.Engine {
|
|||
return t.Format("2006年 01月 02日")
|
||||
},
|
||||
})
|
||||
reader := templates.NewFsTemplate(r.FuncMap)
|
||||
reader.AddTemplate()
|
||||
r.HTMLRender = reader
|
||||
r.HTMLRender = templates.NewFsTemplate(r.FuncMap).AddTemplate()
|
||||
r.Use(middleware.SetStaticFileCache)
|
||||
//gzip 因为一般会用nginx做反代时自动使用gzip,所以go这边本身可以不用
|
||||
/*r.Use(gzip.Gzip(gzip.DefaultCompression, gzip.WithExcludedPaths([]string{
|
||||
|
|
|
@ -20,7 +20,7 @@ func NewFsTemplate(funcMap template.FuncMap) *FsTemplate {
|
|||
return &FsTemplate{FuncMap: funcMap, Templates: make(map[string]*template.Template)}
|
||||
}
|
||||
|
||||
func (t *FsTemplate) AddTemplate() {
|
||||
func (t *FsTemplate) AddTemplate() *FsTemplate {
|
||||
mainTemplates, err := fs.Glob(TemplateFs, "*[^layout]/*.gohtml")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -29,6 +29,7 @@ func (t *FsTemplate) AddTemplate() {
|
|||
name := filepath.Base(include)
|
||||
t.Templates[include] = template.Must(template.New(name).Funcs(t.FuncMap).ParseFS(TemplateFs, include, "layout/*.gohtml"))
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func (t FsTemplate) Instance(name string, data any) render.Render {
|
||||
|
|
Loading…
Reference in New Issue
Block a user