Documentation ¶
Index ¶
- Variables
- type Cache
- func (c *Cache) Build(runtime *garnish.Runtime) error
- func (c *Cache) Grace(window time.Duration) *Cache
- func (c *Cache) KeyLookup(lookup garnish.CacheKeyLookup) *Cache
- func (c *Cache) MaxSize(size int) *Cache
- func (c *Cache) NoSaint() *Cache
- func (c *Cache) PurgeHandler(handler garnish.PurgeHandler) *Cache
- type Configuration
- func (c *Configuration) Address(address string) *Configuration
- func (c *Configuration) Build() (*garnish.Runtime, error)
- func (c *Configuration) BytePool(capacity, count uint32) *Configuration
- func (c *Configuration) Cache() *Cache
- func (c *Configuration) Debug() *Configuration
- func (c *Configuration) DnsTTL(ttl time.Duration) *Configuration
- func (c *Configuration) Fatal(response garnish.Response) *Configuration
- func (c *Configuration) Hydrate(loader garnish.HydrateLoader) *Hydrate
- func (c *Configuration) Insert(position MiddlewarePosition, name string, handler garnish.Middleware) *Configuration
- func (c *Configuration) Logger(logger garnish.Logs) *Configuration
- func (c *Configuration) NotFound(response garnish.Response) *Configuration
- func (c *Configuration) Route(name string) *Route
- func (c *Configuration) Stats() *Stats
- func (c *Configuration) Tweaker(tweaker garnish.RequestTweaker) *Configuration
- func (c *Configuration) Upstream(name string) *Upstream
- type Hydrate
- type MiddlewarePosition
- type Route
- func (r *Route) All(path string) *Route
- func (r *Route) Build(runtime *garnish.Runtime) (*garnish.Route, error)
- func (r *Route) CacheKeyLookup(lookup garnish.CacheKeyLookup) *Route
- func (r *Route) CacheKeyLookupRef(route string) *Route
- func (r *Route) CacheTTL(ttl time.Duration) *Route
- func (r *Route) Delete(path string) *Route
- func (r *Route) FlowHandler(handler garnish.Middleware) *Route
- func (r *Route) Get(path string) *Route
- func (r *Route) Handler(handler garnish.Handler) *Route
- func (r *Route) Head(path string) *Route
- func (r *Route) Method(method string, path string) *Route
- func (r *Route) Options(path string) *Route
- func (r *Route) Patch(path string) *Route
- func (r *Route) Post(path string) *Route
- func (r *Route) Purge(path string) *Route
- func (r *Route) Put(path string) *Route
- func (r *Route) Slow(max time.Duration) *Route
- func (r *Route) Upstream(upstream string) *Route
- type Router
- type Stats
- type Transport
- type Upstream
- func (u *Upstream) Address(address string) *Transport
- func (u *Upstream) Build(runtime *garnish.Runtime, tweaker garnish.RequestTweaker) (garnish.Upstream, error)
- func (u *Upstream) DnsCache(duration time.Duration) *Upstream
- func (u *Upstream) Headers(headers ...string) *Upstream
- func (u *Upstream) Tweaker(tweaker garnish.RequestTweaker) *Upstream
- func (u *Upstream) TweakerRef(upstream string) *Upstream
- type Upstreams
Constants ¶
This section is empty.
Variables ¶
var DefaultHeaders = []string{"Content-Length"}
The default headers to forward to the upstream
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func (*Cache) Grace ¶
If a request is expired but within the grace window, the expired version will be returned. In a background job, the cache will be refreshed. Grace is effective at eliminating the thundering heard problem [1 minute]
func (*Cache) KeyLookup ¶
The function used to generate the primary and secondary cache keys This defaults use the URL for the primary key and the QueryString for the secondary key Having a separate primary and secondary cache key allows us to purge a group of values. For example: primary: /v1/users/32 secondary: "ext=json" and "ext=xml" We can purge all variations associated with /v1/users/32
func (*Cache) NoSaint ¶
Disable saint mode With saint mode, if the upstream returns a 5xx error and a cached response is available, the cached response will be returned regardless of how far expired it is. [saint is enabled by default]
func (*Cache) PurgeHandler ¶
The function which will handle purge requests No default is provided since some level of custom authorization should be done If the handler returns a response, the middleware chain is stopped and the specified response is returned. If the handler does not return a response, the chain continues. This makes it possible to purge the garnish cache while allowing the purge request to be sent to the upstream
type Configuration ¶
type Configuration struct {
// contains filtered or unexported fields
}
Configuration
func LoadConfig ¶
func LoadConfig(path string) (*Configuration, error)
Loads configuration from a toml file
func LoadConfigMap ¶
func LoadConfigMap(m map[string]interface{}) (*Configuration, error)
func LoadConfigTyped ¶
func LoadConfigTyped(t typed.Typed) (*Configuration, error)
func (*Configuration) Address ¶
func (c *Configuration) Address(address string) *Configuration
The address to listen on [:8080]
func (*Configuration) Build ¶
func (c *Configuration) Build() (*garnish.Runtime, error)
Build a runtime object from the configuration, which can then be used to start garnish
func (*Configuration) BytePool ¶
func (c *Configuration) BytePool(capacity, count uint32) *Configuration
The size of each buffer and the number of buffers to keep in a the pool Upstream replies with a content length which fit within the specified capacity wil perform better. The pool is also used for incoming requests with bodies. [65536, 64]
func (*Configuration) Cache ¶
func (c *Configuration) Cache() *Cache
Enable and configure the cache middleware
func (*Configuration) Debug ¶
func (c *Configuration) Debug() *Configuration
Enable debug-level logging
func (*Configuration) DnsTTL ¶
func (c *Configuration) DnsTTL(ttl time.Duration) *Configuration
The default time to cache DNS lookups. Overwritable on a per-upstream basis Even a short value (1s) can help under heavy load [1 minute]
func (*Configuration) Fatal ¶
func (c *Configuration) Fatal(response garnish.Response) *Configuration
The response to return for a 500 [garnish.Empty(500)]
func (*Configuration) Hydrate ¶
func (c *Configuration) Hydrate(loader garnish.HydrateLoader) *Hydrate
Enable and configure the hydration middleware
func (*Configuration) Insert ¶
func (c *Configuration) Insert(position MiddlewarePosition, name string, handler garnish.Middleware) *Configuration
func (*Configuration) Logger ¶
func (c *Configuration) Logger(logger garnish.Logs) *Configuration
Specify a custom logger to use
func (*Configuration) NotFound ¶
func (c *Configuration) NotFound(response garnish.Response) *Configuration
The response to return for a 404 [garnish.Empty(404)]
func (*Configuration) Route ¶
func (c *Configuration) Route(name string) *Route
Configure your routes
func (*Configuration) Stats ¶
func (c *Configuration) Stats() *Stats
Enable and configure the stats middleware
func (*Configuration) Tweaker ¶
func (c *Configuration) Tweaker(tweaker garnish.RequestTweaker) *Configuration
The default function that is used to tweak the http.Request sent to the upstream Overwritable on a per-upstream basis [nul]
func (*Configuration) Upstream ¶
func (c *Configuration) Upstream(name string) *Upstream
Configure upstreams
type Hydrate ¶
type Hydrate struct {
// contains filtered or unexported fields
}
func NewHydrate ¶
func NewHydrate(loader garnish.HydrateLoader) *Hydrate
type MiddlewarePosition ¶
type MiddlewarePosition int
const ( BEFORE_STATS MiddlewarePosition = iota BEFORE_CACHE BEFORE_HYDRATE BEFORE_DISPATCH )
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
func (*Route) All ¶
Register a route for all methods. Can be overwritten on a per-method basis by registering the method-specific route BEFORE specifying the All variant.
func (*Route) CacheKeyLookup ¶
The function used to get the cache key for this route. (overwrites the global Cache's lookup)
func (*Route) CacheKeyLookupRef ¶
Allows the route to reference another route's CacheKeyLookup (based on that route's name). Used by the file-based configuration; when configured programmatically, CacheKeyLookup should be used.
func (*Route) CacheTTL ¶
The amount of time to cachet his request. If not specified, the Cache-Control header will be used (including not caching private). A value < 0 disables the cache for this route
func (*Route) FlowHandler ¶
Specify the handler function
type Stats ¶
type Stats struct {
// contains filtered or unexported fields
}
Configuration for the stats middleware
func (*Stats) Build ¶
In normal usage, there's no need to call this method. Builds the stats middleware into the runtime
type Upstream ¶
type Upstream struct {
// contains filtered or unexported fields
}
func (*Upstream) Address ¶
the address to connect to. Should begin with unix:/ http:// or https:// [""]
func (*Upstream) DnsCache ¶
the duration to cache the upstream's dns lookup. Set to 0 to prevent garnish from caching this value (even a few seconds can help) [1 minute]
func (*Upstream) Headers ¶
The headers to copy from the incoming request to the outgoing request [Content-Length]
func (*Upstream) Tweaker ¶
Custom callback to modify the request (out) that will get sent to the upstream
func (*Upstream) TweakerRef ¶
Allows the upstream to reference another upstream's tweaker (based on that upstream's name). Used by the file-based configuration; when configured programmatically, Tweaker should be used.
type Upstreams ¶
type Upstreams struct {
// contains filtered or unexported fields
}
func NewUpstreams ¶
func NewUpstreams() *Upstreams