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
852 B
Go
37 lines
852 B
Go
package admin
|
|
|
|
import (
|
|
"mygo/admin/assets"
|
|
"net/http"
|
|
"net/url"
|
|
"os"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
)
|
|
|
|
func adminIndex(c echo.Context) error {
|
|
file, err := 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(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("/admin")
|
|
r.GET("/", adminIndex)
|
|
}
|