Documentation ¶
Index ¶
- Variables
- func HTTP2Push(W http.ResponseWriter, target string, headers http.Header) error
- func PrepPath(host, file string) string
- func StringsContainCI(list []string, match string) bool
- type Asset
- type AssetCache
- func (a *AssetCache) Close() error
- func (a *AssetCache) Del(name string)
- func (a *AssetCache) Gen(name string) (*Asset, error)
- func (a *AssetCache) Get(name string) (*Asset, bool)
- func (a *AssetCache) Middleware(h http.HandlerFunc) http.HandlerFunc
- func (a *AssetCache) Serve(res http.ResponseWriter, req *http.Request) error
- func (a *AssetCache) ServeFile(res http.ResponseWriter, req *http.Request, file string) error
- func (a *AssetCache) ServeFileDirect(res http.ResponseWriter, req *http.Request, file string) error
- func (a *AssetCache) ServeHTTP(res http.ResponseWriter, req *http.Request)
- func (a *AssetCache) SetExpiryCheckInterval(interval time.Duration)
- func (a AssetCache) StopExpiryCheckInterval()
- func (a *AssetCache) Update(name string) bool
- type HashMap
Constants ¶
This section is empty.
Variables ¶
var ( // Compressable - list of compressable file types, append to it if needed Compressable = []string{"", ".txt", ".htm", ".html", ".css", ".toml", ".php", ".js", ".json", ".md", ".mdown", ".xml", ".svg", ".go", ".cgi", ".py", ".pl", ".aspx", ".asp"} // AvoidPushing - list of file extentions to skip over when building an http2 push list AvoidPushing = []string{"", ".png", ".webp", ".txt"} )
var ErrAssetNotFound = errors.New(`no asset/file found, cannot serve`)
ErrAssetNotFound is for when an asset cannot be located/created
Functions ¶
func HTTP2Push ¶
HTTP2Push initiates an HTTP/2 server push. This constructs a synthetic request using the target and headers, serializes that request into a PUSH_PROMISE frame, then dispatches that request using the server's request handlec. The target must either be an absolute path (like "/path") or an absolute URL that contains a valid host and the same scheme as the parent request. If the target is a path, it will inherit the scheme and host of the parent request. The headers specifies additional promised request headers. The headers cannot include HTTP/2 pseudo headers like ":path" and ":scheme", which will be added automatically.
func StringsContainCI ¶
StringsContainCI reports whether the lists contains a match regardless of its case.
Types ¶
type Asset ¶
type Asset struct { Ext string Name string ContentType string Loaded time.Time ModTime time.Time Content *bytes.Reader ContentCompressed *bytes.Reader CacheControl string Cache *AssetCache Etag string EtagCompressed string Compressed bool PushList []string }
Asset is an http servable resource
type AssetCache ¶
type AssetCache struct { Dir string Index string NoIndex bool Cache *HashMap Expire time.Duration Interval time.Duration CacheControl string Ticker *time.Ticker DevMode bool Watch bool Watcher *fsnotify.Watcher NotFoundHandler func(http.ResponseWriter, *http.Request) NotFoundError error }
AssetCache is a store for assets
func (*AssetCache) Del ¶
func (a *AssetCache) Del(name string)
Del removes an asset, nb. not the file, the file is fine
func (*AssetCache) Gen ¶
func (a *AssetCache) Gen(name string) (*Asset, error)
Gen generates a new Asset
func (*AssetCache) Middleware ¶
func (a *AssetCache) Middleware(h http.HandlerFunc) http.HandlerFunc
Middleware is a generic go handler that sets up AssetCache like any other static file serving solution on your server
func (*AssetCache) Serve ¶
func (a *AssetCache) Serve(res http.ResponseWriter, req *http.Request) error
Serve is the same as ServeHTTP but it returns the error instead of calling .NotFoundHandler, this is useful for echo/air middleware
func (*AssetCache) ServeFile ¶
func (a *AssetCache) ServeFile(res http.ResponseWriter, req *http.Request, file string) error
ServeFile parses a key/filename and serves it if it exists and returns an ErrAssetNotFound if it doesn't
func (*AssetCache) ServeFileDirect ¶
func (a *AssetCache) ServeFileDirect(res http.ResponseWriter, req *http.Request, file string) error
ServeFileDirect takes a key/filename directly and serves it if it exists and returns an ErrAssetNotFound if it doesn't
func (*AssetCache) ServeHTTP ¶
func (a *AssetCache) ServeHTTP(res http.ResponseWriter, req *http.Request)
ServeHTTP implements the http.Handler interface
func (*AssetCache) SetExpiryCheckInterval ¶
func (a *AssetCache) SetExpiryCheckInterval(interval time.Duration)
SetExpiryCheckInterval generates a new ticker with a set interval
func (AssetCache) StopExpiryCheckInterval ¶
func (a AssetCache) StopExpiryCheckInterval()
StopExpiryCheckInterval stops asset expiration checks
func (*AssetCache) Update ¶
func (a *AssetCache) Update(name string) bool
Update first deletes an asset then gets it again, updating it thereby.