package agent_admin import ( "mygo/agent_admin/agent_assets" "net/http" "net/url" "os" "github.com/labstack/echo/v4" ) func adminIndex(c echo.Context) error { file, err := agent_assets.Static.ReadFile("web/dist/index.html") if err != nil && os.IsNotExist(err) { return c.String(http.StatusNotFound, "not found") } return c.HTML(http.StatusOK, string(file)) } func handlerStatic(c echo.Context) error { staticServer := http.FileServer(http.FS(agent_assets.Static)) c.Request().URL = &url.URL{Path: "web/dist" + c.Request().RequestURI} staticServer.ServeHTTP(c.Response().Writer, c.Request()) return nil } func Register(e *echo.Echo) { //注册路由 e.GET("/css/*filepath", handlerStatic) e.GET("/fonts/*filepath", handlerStatic) e.GET("/img/*filepath", handlerStatic) e.GET("/js/*filepath", handlerStatic) r := e.Group("/agent_admin") r.GET("/", adminIndex) }