kassets

package
v0.0.0-...-5f133c6 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: BSD-3-Clause, BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcceptsEncoding

func AcceptsEncoding(accepts, encoding string) bool

func RegisterAssets

func RegisterAssets(stats *AssetStats, assets map[string][]byte, base string, mapper AssetMapper)

RegisterAssets goes oever each asset supplied, creates an http handler, and registers it with AssetMapper.

assets is a dict generated via a go_embed_data target, basically a map between a path and byte array with the content of the file. base is a string determining the top level directory containing the assets, can be empty. mapper is a function in charge of mapping the asset and detected handler with the mux.

Example: if you set base to be "/data/", assets like "foo/bar/baz/data/test.html" will be mapped as "test.html", all that's after "/data/". Files not containing "/data/" will be skipped.

Types

type AssetMapper

type AssetMapper func(original, name string, handler khttp.FuncHandler) []string

func BasicMapper

func BasicMapper(mapper AssetMapper) AssetMapper

BasicMapper registers the supplied files/assets with a normalized name.

Specifically: - leaves favicon.ico alone. - removes the .html extension. - maps index.html files to /.

func DefaultMapper

func DefaultMapper(mux *http.ServeMux) AssetMapper

func MuxMapper

func MuxMapper(mux *http.ServeMux) AssetMapper

MuxMapper simply registers a path as is with the mux.

func PrefixMapper

func PrefixMapper(prefix string, mapper AssetMapper) AssetMapper

func StripExtensionMapper

func StripExtensionMapper(mapper AssetMapper) AssetMapper

type AssetResource

type AssetResource struct {
	Base string

	Name string
	Mime string

	Size       int
	Compressed int

	Paths []string
}

type AssetStats

type AssetStats struct {
	Skipped []AssetResource
	Mapped  []AssetResource

	Total, Compressed     uint64
	JsTotal, JsCompressed uint64
}

func (*AssetStats) AddCompressed

func (as *AssetStats) AddCompressed(size int)

func (*AssetStats) AddJsCompressed

func (as *AssetStats) AddJsCompressed(size int)

func (*AssetStats) AddJsTotal

func (as *AssetStats) AddJsTotal(size int)

func (*AssetStats) AddMapped

func (as *AssetStats) AddMapped(res AssetResource)

func (*AssetStats) AddSkipped

func (as *AssetStats) AddSkipped(res AssetResource)

func (*AssetStats) AddTotal

func (as *AssetStats) AddTotal(size int)

func (AssetStats) Log

func (as AssetStats) Log(p logger.Printer)

Jump to

Keyboard shortcuts

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