Documentation ¶
Index ¶
- Variables
- func List(baseURL string, opener FileOpener, r io.Reader, mimetype, uri string) ([]string, error)
- func Reader(r io.Reader, parser *Parser, mimetype, uri string) io.Reader
- func Writer(w io.Writer, parser *Parser, mimetype, uri string) *pushingWriter
- type Cache
- type DefaultCache
- type DefaultFileOpener
- type FileOpener
- type FileOpenerFunc
- type ListHandler
- type P
- type Parser
- type PushHandler
- type ResponseWriterCloser
- type URIHandler
- type URIHandlerFunc
Constants ¶
This section is empty.
Variables ¶
var ErrNoParser = errors.New("mimetype has no parser")
ErrNoParser is returned when the mimetype has no parser specified.
var ErrNoPusher = errors.New("ResponseWriter is not a Pusher")
ErrNoPusher is returned when the ResponseWriter does not implement the Pusher interface.
var ErrRecursivePush = errors.New("recursive push")
ErrRecursivePush is returned when the request was initiated by a push. This is determined via the X-Pushed header.
var ExtToMimetype = map[string]string{
"": "text/html",
".html": "text/html",
".css": "text/css",
".svg": "image/svg+xml",
}
ExtToMimetype is an extension -> mimetype mapping used in ResponseWriter when the Content-Type header is not set.
Functions ¶
func List ¶
List parses r with mimetype and served by uri. It returns a list of local resource URIs. If FileOpener is not nil, it will read and parse the referenced URIs recursively.
Types ¶
type Cache ¶
Cache is an interface that allows Middleware and ResponseWriter to cache the results of the list of resources to improve performance.
type DefaultCache ¶
type DefaultCache struct {
// contains filtered or unexported fields
}
func NewDefaultCache ¶
func NewDefaultCache() *DefaultCache
func (*DefaultCache) Add ¶
func (c *DefaultCache) Add(uri string, resource string)
func (*DefaultCache) Del ¶
func (c *DefaultCache) Del(uri string)
type DefaultFileOpener ¶
type DefaultFileOpener struct {
// contains filtered or unexported fields
}
func NewDefaultFileOpener ¶
func NewDefaultFileOpener(basePath string) *DefaultFileOpener
type FileOpener ¶
FileOpener is an interface that allows the parser to load embedded resources recursively.
type FileOpenerFunc ¶
type ListHandler ¶
type ListHandler struct { URIs []string // contains filtered or unexported fields }
ListHandler is a URIHandler that collects all resource URIs in a list.
func NewListHandler ¶
func NewListHandler() *ListHandler
func (*ListHandler) URI ¶
func (h *ListHandler) URI(uri string) error
type P ¶
type P struct {
// contains filtered or unexported fields
}
func (*P) Middleware ¶
Middleware wraps an http.Handler and pushes local resources to the client. If FileOpener is not nil, it will read and parse the referenced URIs recursively. If Cache is not nil, it will cache the URIs found and use it on subsequent requests.
func (*P) ResponseWriter ¶
func (p *P) ResponseWriter(w http.ResponseWriter, r *http.Request) (ResponseWriterCloser, error)
ResponseWriter wraps a ResponseWriter interface. It parses anything written to the returned ResponseWriter and pushes local resources to the client. If FileOpener is not nil, it will read and parse the referenced URIs recursively. If Cache is not nil, it will cache the URIs found and use it on subsequent requests. ResponseWriter can only return ErrNoPusher, ErrRecursivePush or ErrNoParser errors. Parsing errors are returned by Close on the writer. The writer must be closed explicitly.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses resources and calls uriHandler for all found URIs.
func NewParser ¶
func NewParser(rawBaseURL string, opener FileOpener, uriHandler URIHandler) (*Parser, error)
NewParser returns a new Parser. rawBaseURL defines the prefix an URL must have to be considered a local resource. If FileOpener is not nil, it will read and parse the referenced URIs recursively.
func (*Parser) IsRecursive ¶
IsRecursive returns true when the URIs within documents are aso read and parsed.
type PushHandler ¶
type PushHandler struct {
// contains filtered or unexported fields
}
PushHandler is a URIHandler that pushes resources to the client.
func NewPushHandler ¶
func NewPushHandler(pusher http.Pusher, opts *http.PushOptions) *PushHandler
func NewPushHandlerFromResponseWriter ¶
func NewPushHandlerFromResponseWriter(w http.ResponseWriter) (*PushHandler, error)
func (*PushHandler) URI ¶
func (p *PushHandler) URI(uri string) error
type ResponseWriterCloser ¶
type ResponseWriterCloser interface { http.ResponseWriter Close() error }
ResponseWriterCloser makes sure that all data has been written on calling Close (can be blocking).
type URIHandler ¶
URIHandler is a callback definition that is called when a resource URI is found.
type URIHandlerFunc ¶
func (URIHandlerFunc) URI ¶
func (f URIHandlerFunc) URI(uri string) error