Documentation ¶
Index ¶
- Constants
- Variables
- func CreateNodes(links []Link) []*html.Node
- func Do(c *fiber.Ctx, cfg Config, doc *Document) error
- func NewClient(opts ...ClientOpt) *http.Client
- func Template(config Config, name string, bind interface{}, layouts ...string) fiber.Handler
- type ClientOpt
- type Config
- type Document
- type Fragment
- func (f *Fragment) Deferred() bool
- func (f *Fragment) Element() *goquery.Selection
- func (f *Fragment) Fallback() string
- func (f *Fragment) HtmlFragment() *HtmlFragment
- func (f *Fragment) ID() string
- func (f *Fragment) Links() []*html.Node
- func (f *Fragment) Method() string
- func (f *Fragment) Primary() bool
- func (f *Fragment) Ref() string
- func (f *Fragment) Resolve() ResolverFunc
- func (f *Fragment) Src() string
- func (f *Fragment) Timeout() time.Duration
- type Header
- type HtmlFragment
- type Link
- type Resolver
- type ResolverFunc
Constants ¶
const ( StyleSheet = "stylesheet" Script = "script" )
const (
// HTTPLinkHeader is the HTTP header for LINK entities.
HTTPLinkHeader = "Link"
)
Variables ¶
var DefaultClient = NewClient()
DefaultClient is the default http client used
Functions ¶
func Do ¶
Do represents the core functionality of the middleware. It resolves the fragments from a parsed template.
Types ¶
type ClientOpt ¶
ClientOpt is a function which receives a http.Client and returns a http.Client.
func WithTransport ¶
func WithTransport(tr http.RoundTripper) ClientOpt
WithTransport is a helper function to set the transport.
type Config ¶
type Config struct { // Filter defines a function to skip the middleware. // Optional. Default: nil Filter func(*fiber.Ctx) bool // FilterResponse defines a function to filter the responses // from the fragment sources. FilterResponse func(*fasthttp.Response) // FilterRequest defines a function to filter the request // to the fragment sources. FilterRequest func(*fasthttp.Request) // ErrorHandler defines a function which is executed // It may be used to define a custom error. // Optional. Default: 401 Invalid or expired key ErrorHandler fiber.ErrorHandler // FilterHead defines a function to filter the new // nodes in the <head> of the document passed by the LINK header entity. FilterHead func([]*html.Node) []*html.Node // DefaultHost defines the host to use, // if no host is set on a fragment. // Optional. Default: localhost:3000 DefaultHost string // Client defines the http client to use for // fetching the fragments. // Optional. Default: DefaultClient Client *http.Client }
Config ...
type Document ¶
Document ...
func (*Document) HtmlFragment ¶
func (d *Document) HtmlFragment() *HtmlFragment
Fragments is returning the selection of fragments from an HTML page.
func (*Document) SetStatusCode ¶
SetStatusCode is setting the HTTP status code for the document.
func (*Document) StatusCode ¶
StatusCode is getting the HTTP status code for the document.
type Fragment ¶
type Fragment struct {
// contains filtered or unexported fields
}
Fragment is a <fragment> in the <header> or <body> of a HTML page.
func FromSelection ¶
FromSelection creates a new fragment from a fragment selection in the DOM.
func (*Fragment) HtmlFragment ¶
func (f *Fragment) HtmlFragment() *HtmlFragment
HtmlFragment returns embedded fragments of HTML.
func (*Fragment) Links ¶
Links returns the new nodes that go in the head via the LINK HTTP header entity.
func (*Fragment) Primary ¶
Primary denotes a fragment as responsible for setting the response code of the entire HTML page.
func (*Fragment) Resolve ¶
func (f *Fragment) Resolve() ResolverFunc
Resolve is resolving all needed data, setting headers and the status code.
type HtmlFragment ¶
HtmlFragment is representation of HTML fragments.
func NewHtmlFragment ¶
func NewHtmlFragment(root *html.Node) (*HtmlFragment, error)
NewHtmlFragment creates a new fragment of HTML.
func (*HtmlFragment) AppendHead ¶
func (d *HtmlFragment) AppendHead(ns ...*html.Node)
AppendHead ...
func (*HtmlFragment) Fragment ¶
func (h *HtmlFragment) Fragment() *goquery.Document
Document get the full document representation of the HTML fragment.
func (*HtmlFragment) Fragments ¶
func (h *HtmlFragment) Fragments() (map[string]*Fragment, error)
Fragments is returning the selection of fragments from an HTML page.
func (*HtmlFragment) Html ¶
func (h *HtmlFragment) Html() (string, error)
Html creates the HTML output of the created document.