package main
import (
static "github.com/Code-Hex/echo-static"
assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/labstack/echo"
)
func main() {
e := echo.New()
e.Use(static.ServeRoot("/static", NewAssets("assets")))
e.GET("/ping", func(c echo.Context) error {
return c.String(200, "test")
})
// Listen and Server in 0.0.0.0:8080
e.Start(":8080")
}
func NewAssets(root string) *assetfs.AssetFS {
return &assetfs.AssetFS{
Asset: Asset,
AssetDir: AssetDir,
AssetInfo: AssetInfo,
Prefix: root,
}
}
and put your asset file in the assets
directory and execute the following code before compile it.
go-bindata -o bindata.go assets/...
echo-static is File server middleware for go-bindata and echo.
go get github.com/Code-Hex/echo-static