stitcher

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2020 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContentHandler

func ContentHandler(site *Host, route Route) func(http.ResponseWriter, *http.Request)

ContentHandler uses the Source to render content

func InitCache

func InitCache() *http.Server

InitCache sets up the cache service

func RunServer

func RunServer(listenAddress string, hostConfigFiles []string)

RunServer serves up sites specified in hosts

func WaitForSignal

func WaitForSignal(srv *http.Server)

WaitForSignal blocks until SIGINT arrives.

Types

type Content

type Content struct {
	Source   string `hcl:"source,optional"` // URL to fetch the main source
	Selector string `hcl:"select,optional"` // CSS Selector to extract content from - optional

	Replacements []Replacement `hcl:"replacement,block"` // May be empty

	CacheKey string `hcl:"cache,optional"`
	CacheTTL string `hcl:"ttl,optional"`

	Template string `hcl:"template,optional"` // Go template source -- URL
	JSON     string `hcl:"json,optional"`     // Used by templates to retrieve data -- URL
	// contains filtered or unexported fields
}

Content is a piece of content representing a page or portion of a page

func (*Content) Caching

func (c *Content) Caching() bool

Caching returns true if we are to use the endpoint

func (*Content) Fetch

func (c *Content) Fetch(site *Host, contextdata map[string]interface{}) (string, error)

Fetch returns the rendered content (or from endpoint if endpoint is configured for the end point)

func (*Content) InterpolatedCacheKey

func (c *Content) InterpolatedCacheKey(contextData map[string]interface{}) string

InterpolatedCacheKey returns the interpolated endpoint key

func (*Content) Render

func (c *Content) Render(site *Host, contextdata map[string]interface{}) (string, error)

Render loads content from SourceURI and merges an fragements into the resulting document and returns the string representation

type ContentContextValue

type ContentContextValue struct {
	Site        *Host
	Content     *Content
	ContextData map[string]interface{}
}

ContentContextValue is passed via Context.WithValue() to the endpoint Getter Func

type DocumentFetcher

type DocumentFetcher interface {
	Fetch() (string, error)
}

DocumentFetcher are something that retrieves content

type FileFetcher

type FileFetcher struct {
	Path string
}

FileFetcher is a type of Fetcher that loads content from a file.

func (*FileFetcher) Fetch

func (fetcher *FileFetcher) Fetch() (string, error)

Fetch returns an io.ReadCloser for the file

type Host

type Host struct {
	Hostname string `hcl:"hostname"`

	Routes []Route `hcl:"route,block"`

	Cache    *groupcache.Group
	MaxCache int64 `hcl:"max_cache,optional"`
}

Host represents a single VHOSTed site

func ParseHostHCL

func ParseHostHCL(src []byte, filename string) (c *Host, err error)

ParseHostHCL will parse file content into valid Host.

func ReadHostHCL

func ReadHostHCL(filename string) (c *Host, err error)

ReadHostHCL will load and parse a file containing hcl that defines a host

func (*Host) Init

func (host *Host) Init()

Init handles host specific initialization

type RenderedTemplateFetcher

type RenderedTemplateFetcher struct {
	Template      *template.Template
	DataURL       string // URL for the JSON source
	SourceFetcher DocumentFetcher

	RequestContext map[string]interface{}
}

RenderedTemplateFetcher Parses and executes a Go template pulling data from JSONURL (if not empty)

func (*RenderedTemplateFetcher) Fetch

func (fetcher *RenderedTemplateFetcher) Fetch() (string, error)

Fetch returns the rendered template TODO Break this up

type Replacement

type Replacement struct {
	Content Content `hcl:"content,block"`
	At      string  `hcl:",label"`
}

Replacement replaces content at At with Content

type Route

type Route struct {
	Path string `hcl:",label"` // Respond to requests at this path

	Source     *Content `hcl:"content,block"` // URL to fetch the main source
	StaticPath *Static  `hcl:"static,block"`  // URL to fetch the main source

	MaxRate       float64 `hcl:"maxrate,optional"`
	AllowBurst    int     `hcl:"burst,optional"`
	BotMaxRate    float64 `hcl:"botmaxrate,optional"`
	BotAllowBurst int     `hcl:"botburst,optional"`
	// contains filtered or unexported fields
}

Route returns content for a given path

func (*Route) ContentHandler

func (route *Route) ContentHandler(site *Host, w http.ResponseWriter, r *http.Request)

ContentHandler uses the Source to render content

func (*Route) Init

func (route *Route) Init()

Init creates runtime objects for the end point

func (*Route) Throttling

func (route *Route) Throttling(r *http.Request) bool

Throttling returns true if the current request is to be rate limited.

type Static

type Static struct {
	Directory string `hcl:"directory"`
}

Static is for defining static file routes

type StringFetcher

type StringFetcher struct {
	Body string
}

StringFetcher is a type of Fetcher that loads content from a string

func (*StringFetcher) Fetch

func (fetcher *StringFetcher) Fetch() (string, error)

Fetch returns the string

type URIFetcher

type URIFetcher struct {
	URI string
}

URIFetcher is a fetcher from the network (typically http(s))

func (*URIFetcher) Fetch

func (fetcher *URIFetcher) Fetch() (string, error)

Fetch returns res.Body

Jump to

Keyboard shortcuts

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