Documentation
¶
Index ¶
- Constants
- Variables
- func LogFetchResultLoadingError(res *FetchResult, w http.ResponseWriter, r *http.Request)
- func MetadataForRequest(r *http.Request) map[string]interface{}
- func ParseHeadFragment(fragment *StringFragment, headPropertyMap map[string]string) error
- type Cache
- type CacheInvalidationHandler
- type CacheStrategy
- type CachingContentLoader
- type CompositionHandler
- type Content
- type ContentFetcher
- func (fetcher *ContentFetcher) AddFetchJob(d *FetchDefinition)
- func (fetcher *ContentFetcher) Empty() bool
- func (fetcher *ContentFetcher) MetaJSON() map[string]interface{}
- func (fetcher *ContentFetcher) SetFetchDefinitionFactory(factory FetchDefinitionFactory)
- func (fetcher *ContentFetcher) WaitForResults() []*FetchResult
- type ContentFetcherFactory
- type ContentLoader
- type ContentMerge
- type ContentMerger
- type ContentParser
- type ContentV2
- type ContentWrapper
- type DefaultErrorHandler
- type ErrorHandler
- type FetchDefinition
- func (d *FetchDefinition) DiscoveredBy(dnsServer string) *FetchDefinition
- func (fd *FetchDefinition) FromRequest(r *http.Request) *FetchDefinition
- func (def *FetchDefinition) Hash() string
- func (def *FetchDefinition) IsCacheable(responseStatus int, responseHeaders http.Header) bool
- func (def *FetchDefinition) IsReadableFromCache() bool
- func (fd *FetchDefinition) WithHeaders(header http.Header) *FetchDefinition
- func (fd *FetchDefinition) WithName(name string) *FetchDefinition
- func (fd *FetchDefinition) WithPriority(priority int) *FetchDefinition
- func (fd *FetchDefinition) WithResponseProcessor(rp ResponseProcessor) *FetchDefinition
- type FetchDefinitionFactory
- type FetchResult
- type FetchResultSupplier
- type FetchResults
- type FileContentLoader
- type Fragment
- type HtmlContentParser
- type HttpContentLoader
- type IdentityDeduplicationStrategy
- type MemoryContent
- func (c *MemoryContent) Body() map[string]Fragment
- func (c *MemoryContent) BodyAttributes() Fragmentdeprecated
- func (c *MemoryContent) BodyAttributesArray() []html.Attribute
- func (c *MemoryContent) Dependencies() map[string]Params
- func (c *MemoryContent) Head() Fragment
- func (c *MemoryContent) HttpHeader() http.Header
- func (c *MemoryContent) HttpStatusCode() int
- func (c *MemoryContent) MemorySize() int
- func (c *MemoryContent) Meta() map[string]interface{}
- func (c *MemoryContent) Name() string
- func (c *MemoryContent) Reader() io.ReadCloser
- func (c *MemoryContent) RequiredContent() []*FetchDefinition
- func (c *MemoryContent) Tail() Fragment
- type Params
- type ResponseProcessor
- type SimpleDeduplicationStrategy
- type StringFragment
- func (f *StringFragment) AddStylesheets(stylesheets [][]html.Attribute)
- func (f *StringFragment) Content() string
- func (f *StringFragment) Execute(w io.Writer, data map[string]interface{}, ...) error
- func (f *StringFragment) MemorySize() int
- func (f *StringFragment) SetContent(content string)
- func (f *StringFragment) Stylesheets() [][]html.Attribute
- type StylesheetDeduplicationStrategy
Constants ¶
const ( LayoutFragmentName = "layout" FragmentSeparater = "#" DefaultBufferSize = 1024 * 100 )
const ( DefaultTimeout time.Duration = 10 * time.Second FileURLPrefix = "file://" DefaultPriority = 0 )
const ( UicRemove = "uic-remove" UicInclude = "uic-include" UicFetch = "uic-fetch" UicFragment = "uic-fragment" UicTail = "uic-tail" ScriptTypeMeta = "text/uic-meta" ParamAttrPrefix = "param-" )
const ( PlaceholderStart = "§[" PlaceholderEnd = "]§" StartInclude = ">" StartIncludeBlock = "#>" EndIncludeBlock = "/" )
const MAX_PRIORITY int = 4294967295
Variables ¶
var ForwardRequestHeaders = []string{
"Authorization",
"Cache-Control",
"Cookie",
"Content-Length",
"Content-Type",
"If-Match",
"If-Modified-Since",
"If-None-Match",
"If-Range",
"If-Unmodified-Since",
"Pragma",
"Referer",
"Transfer-Encoding",
"X-Forwarded-Host",
"X-Correlation-Id",
"X-Feature-Toggle",
"Host",
}
ForwardRequestHeaders are those headers, which are included from the original client request to the backend request. TODO: Add Host header to an XFF header
var ForwardResponseHeaders = []string{
"Age",
"Allow",
"Cache-Control",
"Content-Disposition",
"Content-Security-Policy",
"Content-Type",
"Date",
"ETag",
"Expires",
"Last-Modified",
"Link",
"Location",
"Pragma",
"Set-Cookie",
"WWW-Authenticate"}
ForwardResponseHeaders are those headers, which are included from the servers backend response to the client.
var ResponseProcessorsNotApplicable = errors.New("request processors are not apliable on file content")
Functions ¶
func LogFetchResultLoadingError ¶
func LogFetchResultLoadingError(res *FetchResult, w http.ResponseWriter, r *http.Request)
func MetadataForRequest ¶
func ParseHeadFragment ¶
func ParseHeadFragment(fragment *StringFragment, headPropertyMap map[string]string) error
Types ¶
type CacheInvalidationHandler ¶
type CacheInvalidationHandler struct {
// contains filtered or unexported fields
}
func NewCacheInvalidationHandler ¶
func NewCacheInvalidationHandler(cache Cache, next http.Handler) *CacheInvalidationHandler
func (*CacheInvalidationHandler) ServeHTTP ¶
func (cih *CacheInvalidationHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type CacheStrategy ¶
type CachingContentLoader ¶
type CachingContentLoader struct {
// contains filtered or unexported fields
}
func NewCachingContentLoader ¶
func NewCachingContentLoader(cache Cache) *CachingContentLoader
func (*CachingContentLoader) Load ¶
func (loader *CachingContentLoader) Load(fd *FetchDefinition) (Content, error)
type CompositionHandler ¶
type CompositionHandler struct {
// contains filtered or unexported fields
}
func NewCompositionHandler ¶
func NewCompositionHandler(contentFetcherFactory ContentFetcherFactory) *CompositionHandler
NewCompositionHandler creates a new Handler with the supplied defaultData, which is used for each request.
func NewCompositionHandlerWithCache ¶
func NewCompositionHandlerWithCache(contentFetcherFactory ContentFetcherFactory, cache Cache) *CompositionHandler
NewCompositionHandlerWithCache creates a new Handler with the supplied defaultData, which is used for each request. Use this constructor, if you created a caching content loader and provide the handle to it's cache as argument.
func (*CompositionHandler) ServeHTTP ¶
func (agg *CompositionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*CompositionHandler) WithCache ¶
func (agg *CompositionHandler) WithCache(cache Cache) *CompositionHandler
func (*CompositionHandler) WithDeduplicationStrategyFactory ¶
func (agg *CompositionHandler) WithDeduplicationStrategyFactory(strategyFactory func() StylesheetDeduplicationStrategy) *CompositionHandler
Set the deduplication strategy to be used by the constructed content merger This method will first take effect in the upcomping call of ServeHTTP()
type Content ¶
type Content interface { // The Name of the content, as given in the fetch definition Name() string // RequiredContent returns a list of Content Elements to load RequiredContent() []*FetchDefinition // Dependencies returns list of referenced content element names. // The list only contains the base names of the includes e.g. 'foo' for '<uic-include src="foo#bar"/>' Dependencies() map[string]Params // Meta returns a data structure to add to the global // data context. Meta() map[string]interface{} // Head returns a partial which should be // inserted to the html head Head() Fragment // Body returns a map of partials, // the named body partials, where the keys are partial names. Body() map[string]Fragment // Tail returns a partial which should be inserted at the end of the page. // e.g. a script to load after rendering. Tail() Fragment // Deprecated: Return the attributes for the body element as Fragment. BodyAttributes() Fragment // Reader returns the stream with the content, of any. // If Reader() == nil, no stream is available an it contains parsed data, only. Reader() io.ReadCloser // HttpHeader() returns the http headers of the fetch job HttpHeader() http.Header // HttpStatusCode() returns the http statuc code of the fetch job HttpStatusCode() int // MemorySize return the estimated size in bytes, for this object in memory MemorySize() int }
Content is the abstraction over includable data. Content may be parsed of it may contain a stream represented by a non nil Reader(), not both.
type ContentFetcher ¶
type ContentFetcher struct { Loader ContentLoader // contains filtered or unexported fields }
ContentFetcher is a type, which can fetch a set of Content pages in parallel.
func NewContentFetcher ¶
func NewContentFetcher(defaultMetaJSON map[string]interface{}) *ContentFetcher
NewContentFetcher creates a ContentFetcher with an HtmlContentParser as default. TODO: The FetchResults should always be returned in a predictable order, independent of the actual response times of the fetch jobs.
func (*ContentFetcher) AddFetchJob ¶
func (fetcher *ContentFetcher) AddFetchJob(d *FetchDefinition)
AddFetchJob adds one job to the fetcher and recursively adds the dependencies also.
func (*ContentFetcher) Empty ¶
func (fetcher *ContentFetcher) Empty() bool
func (*ContentFetcher) MetaJSON ¶
func (fetcher *ContentFetcher) MetaJSON() map[string]interface{}
func (*ContentFetcher) SetFetchDefinitionFactory ¶
func (fetcher *ContentFetcher) SetFetchDefinitionFactory(factory FetchDefinitionFactory)
SetFetchDefinitionFactory supplies a factory for lazy evaluated fetch jobs, which will only be loaded if a fragment refrences them. Seting the factory of optional, but if used, has to be done before adding Jobs by AddFetchJob.
func (*ContentFetcher) WaitForResults ¶
func (fetcher *ContentFetcher) WaitForResults() []*FetchResult
Wait blocks until all jobs are done, either successful or with an error result and returns the content and errors. Do we need to return the Results in a special order????
type ContentFetcherFactory ¶
type ContentFetcherFactory func(r *http.Request) FetchResultSupplier
A ContentFetcherFactory returns a configured fetch job for a request which can return the fetch results.
type ContentLoader ¶
type ContentLoader interface { // Load synchronously loads a content. // The loader has to ensure to return the call withing the supplied timeout. Load(fd *FetchDefinition) (content Content, err error) }
type ContentMerge ¶
type ContentMerge struct { MetaJSON map[string]interface{} Head []Fragment BodyAttrs []Fragment BodyAttrsArray [][]html.Attribute // Aggregator for the Body Fragments of the results. // Each fragment is insertes twice with full name and local name, // The full name only ends with a FragmentSeparater ('#'), if the local name is not empty // and the local name is always prefixed with FragmentSeparater ('#'). Body map[string]Fragment // Aggregator for the Tail Fragments of the results. Tail []Fragment Buffered bool // contains filtered or unexported fields }
ContentMerge is a helper type for creation of a combined html document out of multiple Content pages.
func NewContentMerge ¶
func NewContentMerge(metaJSON map[string]interface{}) *ContentMerge
NewContentMerge creates a new buffered ContentMerge
func (*ContentMerge) AddContent ¶
func (cntx *ContentMerge) AddContent(c Content, priority int)
func (*ContentMerge) GetBodyFragmentByName ¶
func (cntx *ContentMerge) GetBodyFragmentByName(name string) (Fragment, bool)
GetBodyFragmentByName returns a fragment by ists name. If the name does not contain a FragmentSeparater ('#'), and no such fragment is found. also a lookup for '#name' is done, to check, if there is a local name matching. The bool return value indicates, if the fragment was found.
func (*ContentMerge) GetHtml ¶
func (cntx *ContentMerge) GetHtml() ([]byte, error)
func (*ContentMerge) SetDeduplicationStrategy ¶
func (cntx *ContentMerge) SetDeduplicationStrategy(strategy StylesheetDeduplicationStrategy)
type ContentMerger ¶
type ContentMerger interface { // Add content to the merger AddContent(c Content, priority int) // Return the html as byte array GetHtml() ([]byte, error) // Set the stratgy for stylesheet deduplication SetDeduplicationStrategy(stategy StylesheetDeduplicationStrategy) }
type ContentParser ¶
type ContentParser interface { // Parse parses the input stream into a Content Object Parse(*MemoryContent, io.Reader) error }
type ContentWrapper ¶
type ContentWrapper struct { Content // contains filtered or unexported fields }
func (*ContentWrapper) Reader ¶
func (cw *ContentWrapper) Reader() io.ReadCloser
type DefaultErrorHandler ¶
type DefaultErrorHandler struct { }
the default handler throws an status 502
func NewDefaultErrorHandler ¶
func NewDefaultErrorHandler() *DefaultErrorHandler
func (*DefaultErrorHandler) Handle ¶
func (der *DefaultErrorHandler) Handle(err error, status int, w http.ResponseWriter, r *http.Request)
type ErrorHandler ¶
type FetchDefinition ¶
type FetchDefinition struct { // The name of the fetch definition Name string URL string Timeout time.Duration FollowRedirects bool Required bool Header http.Header Method string Body io.Reader RespProc ResponseProcessor ErrHandler ErrorHandler CacheStrategy CacheStrategy ServiceDiscoveryActive bool ServiceDiscovery servicediscovery.ServiceDiscovery Priority int }
FetchDefinition is a descriptor for fetching Content from an endpoint.
func NewFetchDefinition ¶
func NewFetchDefinition(url string) *FetchDefinition
Creates a fetch definition (warning: this one will not forward any request headers).
func (*FetchDefinition) DiscoveredBy ¶
func (d *FetchDefinition) DiscoveredBy(dnsServer string) *FetchDefinition
Fluent-interface decorator for the FetchDefinition that activates the ServiceDiscovery
func (*FetchDefinition) FromRequest ¶
func (fd *FetchDefinition) FromRequest(r *http.Request) *FetchDefinition
Use a given request to extract a path, method and body for the fetch request
func (*FetchDefinition) Hash ¶
func (def *FetchDefinition) Hash() string
Hash returns a unique hash for the fetch request. If two hashes of fetch resources are equal, they refer the same resource and can e.g. be taken as replacement for each other. E.g. in case of caching.
func (*FetchDefinition) IsCacheable ¶
func (def *FetchDefinition) IsCacheable(responseStatus int, responseHeaders http.Header) bool
func (*FetchDefinition) IsReadableFromCache ¶
func (def *FetchDefinition) IsReadableFromCache() bool
func (*FetchDefinition) WithHeaders ¶
func (fd *FetchDefinition) WithHeaders(header http.Header) *FetchDefinition
Copy headers to the fetchdefinition (but only the ones which are part of the whitelist)
func (*FetchDefinition) WithName ¶
func (fd *FetchDefinition) WithName(name string) *FetchDefinition
Set a name to be used in the merge context later on
func (*FetchDefinition) WithPriority ¶
func (fd *FetchDefinition) WithPriority(priority int) *FetchDefinition
Priority is used to determine which property from which head has to be taken by collision of multiple fetches
func (*FetchDefinition) WithResponseProcessor ¶
func (fd *FetchDefinition) WithResponseProcessor(rp ResponseProcessor) *FetchDefinition
If a ResponseProcessor-Implementation is given it can be used to change the response before composition
type FetchDefinitionFactory ¶
type FetchDefinitionFactory func(name string, params Params) (fd *FetchDefinition, existing bool, err error)
FetchDefinitionFactory should return a fetch definition for the given name and parameters. This factory method can be used to supply lazy loaded fetch jobs. The FetchDefinition returned has to have the same name as the supplied name parameter. If no fetch definition for the supplied name can be provided by the factory, existing=false is returned, otherwise existing=true.
type FetchResult ¶
type FetchResult struct { Def *FetchDefinition Err error Content Content Hash string // the hash of the FetchDefinition }
type FetchResultSupplier ¶
type FetchResultSupplier interface { // WaitForResults returns all results of a fetch job in a blocking manger. WaitForResults() []*FetchResult // MetaJSON returns the composed meta JSON object MetaJSON() map[string]interface{} // True, if no fetch jobs were added Empty() bool }
type FetchResults ¶
type FetchResults []*FetchResult
Provide implementation for sorting FetchResults by priority with sort.Sort
func (FetchResults) Len ¶
func (fr FetchResults) Len() int
func (FetchResults) Less ¶
func (fr FetchResults) Less(i, j int) bool
func (FetchResults) Swap ¶
func (fr FetchResults) Swap(i, j int)
type FileContentLoader ¶
type FileContentLoader struct {
// contains filtered or unexported fields
}
func NewFileContentLoader ¶
func NewFileContentLoader() *FileContentLoader
func (*FileContentLoader) Load ¶
func (loader *FileContentLoader) Load(fd *FetchDefinition) (Content, error)
type Fragment ¶
type Fragment interface { Execute(w io.Writer, data map[string]interface{}, executeNestedFragment func(nestedFragmentName string) error) error // MemorySize return the estimated size in bytes, for this object in memory MemorySize() int // Return the list of stylesheets used in this fragment Stylesheets() [][]html.Attribute }
type HtmlContentParser ¶
type HtmlContentParser struct { }
func (*HtmlContentParser) Parse ¶
func (parser *HtmlContentParser) Parse(c *MemoryContent, in io.Reader) error
type HttpContentLoader ¶
type HttpContentLoader struct {
// contains filtered or unexported fields
}
func NewHttpContentLoader ¶
func NewHttpContentLoader() *HttpContentLoader
func (*HttpContentLoader) Load ¶
func (loader *HttpContentLoader) Load(fd *FetchDefinition) (Content, error)
TODO: Should we filter the headers, which we forward here, or is it correct to copy all of them?
type IdentityDeduplicationStrategy ¶
type IdentityDeduplicationStrategy struct { }
NOOP strategy. This strategy will insert all found stylesheets w/o any filtering.
func (*IdentityDeduplicationStrategy) Deduplicate ¶
func (strategy *IdentityDeduplicationStrategy) Deduplicate(stylesheets [][]html.Attribute) [][]html.Attribute
type MemoryContent ¶
type MemoryContent struct {
// contains filtered or unexported fields
}
func NewMemoryContent ¶
func NewMemoryContent() *MemoryContent
func (*MemoryContent) Body ¶
func (c *MemoryContent) Body() map[string]Fragment
func (*MemoryContent) BodyAttributes
deprecated
func (c *MemoryContent) BodyAttributes() Fragment
Deprecated: This method is deprecated
func (*MemoryContent) BodyAttributesArray ¶
func (c *MemoryContent) BodyAttributesArray() []html.Attribute
func (*MemoryContent) Dependencies ¶
func (c *MemoryContent) Dependencies() map[string]Params
func (*MemoryContent) Head ¶
func (c *MemoryContent) Head() Fragment
func (*MemoryContent) HttpHeader ¶
func (c *MemoryContent) HttpHeader() http.Header
func (*MemoryContent) HttpStatusCode ¶
func (c *MemoryContent) HttpStatusCode() int
func (*MemoryContent) MemorySize ¶
func (c *MemoryContent) MemorySize() int
func (*MemoryContent) Meta ¶
func (c *MemoryContent) Meta() map[string]interface{}
func (*MemoryContent) Name ¶
func (c *MemoryContent) Name() string
func (*MemoryContent) Reader ¶
func (c *MemoryContent) Reader() io.ReadCloser
func (*MemoryContent) RequiredContent ¶
func (c *MemoryContent) RequiredContent() []*FetchDefinition
func (*MemoryContent) Tail ¶
func (c *MemoryContent) Tail() Fragment
type ResponseProcessor ¶
type SimpleDeduplicationStrategy ¶
type SimpleDeduplicationStrategy struct { }
Simple strategy Implements a very simple deduplication strategy. That is, it filters out stylesheets with duplicate href value.
func (*SimpleDeduplicationStrategy) Deduplicate ¶
func (strategy *SimpleDeduplicationStrategy) Deduplicate(stylesheets [][]html.Attribute) (result [][]html.Attribute)
Remove duplicate entries from hrefs.
type StringFragment ¶
type StringFragment struct {
// contains filtered or unexported fields
}
StringFragment is a simple template based representation of a fragment.
func NewStringFragment ¶
func NewStringFragment(c string) *StringFragment
func (*StringFragment) AddStylesheets ¶
func (f *StringFragment) AddStylesheets(stylesheets [][]html.Attribute)
func (*StringFragment) Content ¶
func (f *StringFragment) Content() string
func (*StringFragment) MemorySize ¶
func (f *StringFragment) MemorySize() int
MemorySize return the estimated size in bytes, for this object in memory
func (*StringFragment) SetContent ¶
func (f *StringFragment) SetContent(content string)
func (*StringFragment) Stylesheets ¶
func (f *StringFragment) Stylesheets() [][]html.Attribute
Source Files
¶
- cache_invalidation_handler.go
- cache_loader.go
- composition_handler.go
- content_fetcher.go
- content_merge.go
- discovered_fetch_definition.go
- fetch_definition.go
- file_content_loader.go
- html_content_parser.go
- http_content_loader.go
- interfaces.go
- memory_content.go
- string_fragment.go
- stylesheet_deduplication.go
- templating.go