static

package
v0.5.9 Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Prefix = ""
)

Functions

func File

func File(file string) echo.HandlerFunc

func FileServer added in v0.5.8

func FileServer(root FileSystem) http.Handler

FileServer is a drop-in replacement for Go's standard http.FileServer which adds support for static resources precompressed with gzip, at the cost of removing the support for directory browsing.

If file filename.ext has a compressed version filename.ext.gz alongside it, if the client indicates that it accepts gzip-compressed data, and if the .gz file can be opened, then the compressed version of the file will be sent to the client. Otherwise the request is passed on to http.ServeContent, and the raw (uncompressed) version is used.

It is up to you to ensure that the compressed and uncompressed versions of files match and have sensible timestamps.

Compressed or not, requests are fulfilled using http.ServeContent, and details like accept ranges and content-type sniffing are handled by that method.

func Static added in v0.5.8

func Static(e *echo.Echo, prefix string, sessionMW echo.MiddlewareFunc)

Types

type Dir added in v0.5.8

type Dir string

Dir is a replacement for the http.Dir type, and implements FileSystem.

func (Dir) Exists added in v0.5.8

func (d Dir) Exists(name string) bool

Exists tests whether a file with the specified name exists, resolved relative to the base directory.

func (Dir) Open added in v0.5.8

func (d Dir) Open(name string) (http.File, error)

Open defers to http.Dir's Open so that gzipped.Dir implements http.FileSystem.

type FileSystem added in v0.5.8

type FileSystem interface {
	http.FileSystem
	Exists(string) bool
}

FileSystem is a wrapper around the http.FileSystem interface, adding a method to let us check for the existence of files without (attempting to) open them.

Jump to

Keyboard shortcuts

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