gin_adapter

package
v3.4.6 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GinAssets

type GinAssets servefiles.Assets

GinAssets is merely an adapter for servefiles.Assets with the same API and with an additional HandlerFunc method.

func NewAssetHandler

func NewAssetHandler(assetPath string) *GinAssets

NewAssetHandler creates an Assets value. The parameter is the directory containing the asset files; this can be absolute or relative to the directory in which the server process is started.

This function cleans (i.e. normalises) the asset path.

func NewAssetHandlerFS

func NewAssetHandlerFS(fs afero.Fs) *GinAssets

NewAssetHandlerFS creates an Assets value for a given filesystem.

func (*GinAssets) HandlerFunc

func (a *GinAssets) HandlerFunc(paramName string) gin.HandlerFunc

HandlerFunc gets the asset handler as a Gin handler. The handler is registered using a catch-all path such as "/files/*filepath". The name of the catch-all parameter is passed in here (for example "filepath").

func (GinAssets) StripOff

func (a GinAssets) StripOff(unwantedPrefixSegments int) *GinAssets

StripOff alters the handler to strip off a specified number of segments from the path before looking for the matching asset. For example, if StripOff(2) has been applied, the requested path "/a/b/c/d/doc.js" would be shortened to "c/d/doc.js".

The returned handler is a new copy of the original one.

func (GinAssets) WithMaxAge

func (a GinAssets) WithMaxAge(maxAge time.Duration) *GinAssets

WithMaxAge alters the handler to set the specified max age on the served assets.

The returned handler is a new copy of the original one.

func (GinAssets) WithNotFound

func (a GinAssets) WithNotFound(notFound http.Handler) *GinAssets

WithNotFound alters the handler so that 404-not found cases are passed to a specified handler. Without this, the default handler is the one provided in the net/http package.

The returned handler is a new copy of the original one.

func (GinAssets) WithSPA added in v3.4.6

func (a GinAssets) WithSPA() *GinAssets

WithSPA alters the handler so that all requestet files without a file extention instead return index.html

The returned handler is a new copy of the original one.

Jump to

Keyboard shortcuts

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