staticserve

package
v0.105.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handle added in v0.83.0

func Handle(fpath string, data []byte, handleFn HandleFunc) (uri string, err error)

func HandleFS added in v0.83.0

func HandleFS(fsys fs.FS, root, fpath string, handleFn HandleFunc) (uri string, err error)

func WalkDir added in v0.70.0

func WalkDir(fsys fs.FS, root string, fn func(filename string, ss *StaticServe) (err error)) (err error)

WalkDir walks the file tree rooted at root, calling fn for each file in the tree with the filename having root trimmed (e.g. "root/dir/file.ext" becomes "dir/file.ext").

Types

type HandleFunc added in v0.83.0

type HandleFunc = func(uri string, handler http.Handler)

HandleFunc matches the signature of http.ServeMux.Handle(), but is called without method or parameters for the pattern. E.g. ("/static/filename.1234567.js").

type StaticServe

type StaticServe struct {
	Name        string
	ContentType string
	Gz          []byte
}

func New

func New(filename string, data []byte) (ss *StaticServe, err error)

New returns a StaticServe that serves the given data with a filename like 'filename.12345678.ext'. The filename must have the suffix ".gz" if the data is GZip compressed. The ".gz" suffix will not be part of the filename presented in this case.

func NewFS added in v0.82.0

func NewFS(fsys fs.FS, fpath string) (ss *StaticServe, err error)

NewFS reads the file at fpath from fsys and then calls New with the filename part of fpath.

func (*StaticServe) ServeHTTP

func (ss *StaticServe) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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