wp-go/route/route.go

40 lines
914 B
Go
Raw Normal View History

2022-09-01 02:31:11 +00:00
package route
import (
"github.com/gin-gonic/gin"
2022-09-13 03:23:28 +00:00
"github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/static"
"html/template"
"net/http"
"strings"
2022-09-01 02:31:11 +00:00
)
func SetupRouter() *gin.Engine {
// Disable Console Color
// gin.DisableConsoleColor()
r := gin.Default()
2022-09-13 03:23:28 +00:00
r.Use(setStaticFileCache)
r.SetFuncMap(template.FuncMap{"unescaped": func(s string) interface{} {
return template.HTML(s)
}})
f := static.Fs{FS: static.FsEx, Path: "wp-includes"}
r.StaticFS("/wp-includes", http.FS(f))
r.StaticFS("/wp-content", http.FS(static.Fs{
FS: static.FsEx,
Path: "wp-content",
}))
2022-09-01 02:31:11 +00:00
r.LoadHTMLGlob("templates/*")
2022-09-13 03:23:28 +00:00
2022-09-01 02:31:11 +00:00
// Ping test
r.GET("/", index)
return r
}
2022-09-13 03:23:28 +00:00
func setStaticFileCache(c *gin.Context) {
f := strings.Split(strings.TrimLeft(c.FullPath(), "/"), "/")
if len(f) > 1 && helper.IsContainInArr(f[0], []string{"wp-includes", "wp-content"}) {
c.Header("Cache-Control", "private, max-age=86400")
}
}