Documentation
¶
Overview ¶
Package fileserver provides HTTP handlers and middleware for serving files from a local directory.
Index ¶
- func NewContentTypeHandler(opts *ContentTypeOptions, next http.Handler) (http.Handler, error)
- func NewFileServerHandler(opts *FileServerOptions) (http.Handler, error)
- func NewWithHeadersHandler(headers map[string]string, next http.Handler) (http.Handler, error)
- type ContentTypeOptions
- type FileServerOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewContentTypeHandler ¶
NewContentTypeHandler returns a middleware handler that sets the "Content-Type" header for requests whose URI file extension is a key in 'opts.Matches', before invoking 'next'.
func NewFileServerHandler ¶
func NewFileServerHandler(opts *FileServerOptions) (http.Handler, error)
NewFileServerHandler returns a handler that serves files from the directory 'opts.Root', optionally wrapped with gzip compression and CORS support. It returns an error if 'opts.Root' is not a directory.
Types ¶
type ContentTypeOptions ¶
type ContentTypeOptions struct {
// Matches maps file extensions (including the leading ".") to the Content-Type header values to set.
Matches map[string]string
}
ContentTypeOptions defines configuration options for the handler returned by NewContentTypeHandler.
type FileServerOptions ¶
type FileServerOptions struct {
// Root is the path of the directory to serve files from.
Root string
// EnableCORS is a boolean flag to enable CORS support.
EnableCORS bool
// CORSOrigins is the list of origins allowed by CORS requests.
CORSOrigins []string
// EnableGzip is a boolean flag to enable gzip compression of responses.
EnableGzip bool
}
FileServerOptions defines configuration options for the handler returned by NewFileServerHandler.