FileSystem
Examples
Import the middleware package that is part of the
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/filesystem"
)
// Provide a minimal config
app.Use(filesystem.New(filesystem.Config{
Root: http.Dir("./assets")
}))
// Or extend your config for customization
app.Use(filesystem.New(filesystem.Config{
Root: http.Dir("./assets"),
Index: "index.html",
Browse: true,
NotFoundFile: "404.html"
}))
Default Config
var ConfigDefault = Config{
Next: nil,
Root: nil,
Index: "/index.html",
Browse: false,
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/filesystem"
"github.com/gobuffalo/packr/v2"
)
func main() {
app := fiber.New()
app.Use("/assets", filesystem.New(filesystem.Config{
Root: packr.New("Assets Box", "/assets"),
})
app.Listen(":3000")
}
go.rice
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/filesystem"
"<Your go module>/myEmbeddedFiles"
)
func main() {
app := fiber.New()
app.Use("/assets", filesystem.New(filesystem.Config{
Root: myEmbeddedFiles.HTTP,
app.Listen(":3000")
}
statik
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/filesystem"
"<Your go module>/statik"
fs "github.com/rakyll/statik/fs"
)
func main() {
statik, err := fs.New()
if err != nil {
panic(err)
}
app := fiber.New()
app.Use("/", filesystem.New(filesystem.Config{
Root: statikFS,
})
app.Listen(":3000")