assetserver

package
v2.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware func(next http.Handler) http.Handler

Middleware defines a HTTP middleware that can be applied to the AssetServer. The handler passed as next is the next handler in the chain. One can decide to call the next handler or implement a specialized handling.

func ChainMiddleware

func ChainMiddleware(middleware ...Middleware) Middleware

ChainMiddleware allows chaining multiple middlewares to one middleware.

type Options

type Options struct {
	// Assets defines the static assets to be used. A GET request is first tried to be served from this Assets. If the Assets returns
	// `os.ErrNotExist` for that file, the request handling will fallback to the Handler and tries to serve the GET
	// request from it.
	//
	// If set to nil, all GET requests will be forwarded to Handler.
	Assets fs.FS

	// Handler will be called for every GET request that can't be served from Assets, due to `os.ErrNotExist`. Furthermore all
	// non GET requests will always be served from this Handler.
	//
	// If not defined, the result is the following in cases where the Handler would have been called:
	//   GET request:   `http.StatusNotFound`
	//   Other request: `http.StatusMethodNotAllowed`
	Handler http.Handler

	// Middleware is a HTTP Middleware which allows to hook into the AssetServer request chain. It allows to skip the default
	// request handler dynamically, e.g. implement specialized Routing etc.
	// The Middleware is called to build a new `http.Handler` used by the AssetSever and it also receives the default
	// handler used by the AssetServer as an argument.
	//
	// If not defined, the default AssetServer request chain is executed.
	//
	// Multiple Middlewares can be chained together with:
	//   ChainMiddleware(middleware ...Middleware) Middleware
	Middleware Middleware
}

Options defines the configuration of the AssetServer.

func (Options) Validate

func (o Options) Validate() error

Validate the options

Jump to

Keyboard shortcuts

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