liuhaijun e94826ce29 add server
Change-Id: I0760f17f6a01c0121b59fcbfafc666032dbc30af
2024-09-19 09:44:15 +00:00

28 lines
798 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package vue
import (
"embed"
"git.inspur.com/sbg-jszt/cfn/cfn-schedule/internal/middleware"
"github.com/gin-gonic/gin"
"net/http"
)
//go:embed static/dist
var f embed.FS
func AddVueRouter(r *gin.Engine) {
r.Use(middleware.Serve("/", middleware.EmbedFolder(f, "static/dist")))
r.NoRoute(func(c *gin.Context) {
data, err := f.ReadFile("static/dist/index.html")
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
return
}
c.Data(http.StatusOK, "text/html; charset=utf-8", data)
})
//if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
// v.RegisterValidation("NameValid", validator_my.NameValid) // 注册自定义验证器名字要和使用的地方的名字保持一致这里就因为NameValid错写成name卡了一个小时
//}
}