filesystem

package
v3.0.0-...-2834d1d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{
	Next:               nil,
	Root:               nil,
	PathPrefix:         ".",
	Browse:             false,
	Index:              "/index.html",
	MaxAge:             0,
	ContentTypeCharset: "",
}

ConfigDefault is the default config

Functions

func New

func New(config ...Config) fiber.Handler

New creates a new middleware handler.

filesystem does not handle url encoded values (for example spaces) on it's own. If you need that functionality, set "UnescapePath" in fiber.Config

func SendFile

func SendFile(c fiber.Ctx, filesystem fs.FS, path string) error

SendFile serves a file from an fs.FS filesystem at the specified path. It handles content serving, sets appropriate headers, and returns errors when needed. Usage: err := SendFile(ctx, fs, "/path/to/file.txt")

Types

type Config

type Config struct {
	// Next defines a function to skip this middleware when returned true.
	//
	// Optional. Default: nil
	Next func(c fiber.Ctx) bool

	// Root is a FileSystem that provides access
	// to a collection of files and directories.
	//
	// Required. Default: nil
	Root fs.FS `json:"-"`

	// PathPrefix defines a prefix to be added to a filepath when
	// reading a file from the FileSystem.
	//
	// Optional. Default "."
	PathPrefix string `json:"path_prefix"`

	// Enable directory browsing.
	//
	// Optional. Default: false
	Browse bool `json:"browse"`

	// Index file for serving a directory.
	//
	// Optional. Default: "index.html"
	Index string `json:"index"`

	// When set to true, enables direct download for files.
	//
	// Optional. Default: false.
	Download bool `json:"download"`

	// The value for the Cache-Control HTTP-header
	// that is set on the file response. MaxAge is defined in seconds.
	//
	// Optional. Default value 0.
	MaxAge int `json:"max_age"`

	// File to return if path is not found. Useful for SPA's.
	//
	// Optional. Default: ""
	NotFoundFile string `json:"not_found_file"`

	// The value for the Content-Type HTTP-header
	// that is set on the file response
	//
	// Optional. Default: ""
	ContentTypeCharset string `json:"content_type_charset"`
}

Config defines the config for middleware.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL