You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
888 B
Go

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)
}