package frontend import ( "embed" "io" "io/fs" "net/http" "github.com/labstack/echo/v4" ) //go:embed frontend/hass_frontend var root embed.FS var RootFS fs.FS var FSHandler echo.HandlerFunc func AliasHandler(toFile string) echo.HandlerFunc { return func(c echo.Context) error { file, err := RootFS.Open(toFile) if err != nil { return err } defer file.Close() b, err := io.ReadAll(file) if err != nil { return err } return c.HTML(http.StatusOK, string(b)) } } func init() { var err error RootFS, err = fs.Sub(root, "frontend/hass_frontend") if err != nil { panic(err) } FSHandler = echo.StaticDirectoryHandler(RootFS, false) }