command

package
v0.0.0-...-e5281c0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2013 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Limit type by the amount of requests in a given time period.
	UnitTypeRequests = iota
	// Limit type by the amount by used bandwidth.
	UnitTypeKilobytes = iota
)

Variables

This section is empty.

Functions

func AddRemoveHeadersFromDict

func AddRemoveHeadersFromDict(in map[string]interface{}) (http.Header, []string, error)

func EndpointsFromUpstreams

func EndpointsFromUpstreams(upstreams []*Upstream) []loadbalance.Endpoint

func NewCommandFromObj

func NewCommandFromObj(in interface{}) (interface{}, error)

func NewForwardFromDict

func NewForwardFromDict(in map[string]interface{}) (interface{}, error)

func NewHeadersFromObj

func NewHeadersFromObj(in interface{}) (http.Header, error)

func NewHeadersListFromObj

func NewHeadersListFromObj(in interface{}) ([]string, error)

func NewRatesFromObj

func NewRatesFromObj(in interface{}) (map[string][]*Rate, error)

func NewReplyFromDict

func NewReplyFromDict(in map[string]interface{}) (interface{}, error)

func PeriodFromString

func PeriodFromString(u string) (time.Duration, error)

func UnitTypeFromString

func UnitTypeFromString(u string) (int, error)

func UnitTypeToString

func UnitTypeToString(u int) string

Types

type AllUpstreamsDownError

type AllUpstreamsDownError struct {
}

func (*AllUpstreamsDownError) Error

func (r *AllUpstreamsDownError) Error() string

type Endpoint

type Endpoint struct {
	Upstream *Upstream
	Eid      string
	Active   bool
}

func NewEndpoint

func NewEndpoint(upstream *Upstream, active bool) *Endpoint

func (*Endpoint) Id

func (e *Endpoint) Id() string

func (*Endpoint) IsActive

func (e *Endpoint) IsActive() bool

type Failover

type Failover struct {
	// Whether to activate the failover for the given request
	Active bool
	// Whenever vulcan encounters one of the http error codes from the upstream,
	// it will initiate a failover instead of proxying the response back to the
	// client, that allows for graceful restarts of the service without timeouts/service disruptions
	Codes []int
}

Failover instructions enable/disable failover and provide more control over the process

func NewFailoverFromDict

func NewFailoverFromDict(in map[string]interface{}) (*Failover, error)

func NewFailoverFromObj

func NewFailoverFromObj(in interface{}) (*Failover, error)

type Forward

type Forward struct {
	// Allows proxy to fall back to the next upstream
	// if the selected upstream failed
	Failover *Failover
	// Each rate key represents a resource to limit, e.g. ip address or account id
	// or a combination of both. Key is a string with a list of rates attached to it.
	// If any of the given rates of the reuqest is exceeded, the request will be not allowed.
	Rates map[string][]*Rate
	// List of upstreams that can accept this request. Load balancer will
	// choose an upstream based on the algo, e.g. random, round robin,
	// or least connections. At least one upstream is required.
	Upstreams []*Upstream
	// If supplied, headers will be added to the proxied request.
	AddHeaders http.Header
	// These headers will be removed from the request header if met, note that
	// hop headers will be removed no matter what.
	RemoveHeaders []string
	// If not emtpy, the original request path will be replaced with the supplied path
	RewritePath string
}

Forward reply tells proxy to forward the request to the given upstreams

func NewForward

func NewForward(
	failover *Failover,
	rates map[string][]*Rate,
	upstreams []*Upstream,
	addHeaders http.Header,
	removeHeaders []string) (*Forward, error)

type Rate

type Rate struct {
	// The amount of unit (e.g. 100 for 100 Kilobytes)
	Units int64
	// Rate's period of time (e.g. second in 100 request/second)
	Period time.Duration
	// Unit to measure, e.g. requests or kilobytes
	UnitType int
}

Rates the information on how many hits or bytes per period of time any endpoint can accept.

func NewRate

func NewRate(units int64, period time.Duration, unitType int) (*Rate, error)

func NewRateFromDict

func NewRateFromDict(in map[string]interface{}) (*Rate, error)

func NewRateFromObj

func NewRateFromObj(in interface{}) (*Rate, error)

func NewRateFromString

func NewRateFromString(in string) (*Rate, error)

func (*Rate) CurrentBucket

func (r *Rate) CurrentBucket(t time.Time) time.Time

Returns epochSeconds rounded to the rate period e.g. minutes rate would return epoch seconds with seconds set to zero hourly rate would return epoch seconds with minutes and seconds set to zero

func (*Rate) NextBucket

func (r *Rate) NextBucket(t time.Time) time.Time

Returns the epoch seconds of the begining of the next time bucket

func (*Rate) RetrySeconds

func (r *Rate) RetrySeconds(now time.Time) int

Calculates when this rate can be hit the next time from the given time t, assuming all the requests in the given

func (*Rate) String

func (r *Rate) String() string

type Reply

type Reply struct {
	// HTTP status code
	Code int
	// Body that should be json serializable
	Body interface{}
}

Reply command tells proxy to reply with a special code and body and do not forward the request.

type RetryError

type RetryError struct {
	Seconds int
}

func (*RetryError) Error

func (r *RetryError) Error() string

type Upstream

type Upstream struct {
	Scheme  string
	Host    string
	Port    int
	Id      string
	Metrics *metrics.UpstreamMetrics
}

Upstream is HTTP server that will actually serve the request that would be proxied

func NewUpstream

func NewUpstream(scheme string, host string, port int) (*Upstream, error)

func NewUpstreamFromDict

func NewUpstreamFromDict(in map[string]interface{}) (*Upstream, error)

func NewUpstreamFromObj

func NewUpstreamFromObj(in interface{}) (*Upstream, error)

func NewUpstreamFromString

func NewUpstreamFromString(in string) (*Upstream, error)

func NewUpstreamFromUrl

func NewUpstreamFromUrl(url *url.URL) (*Upstream, error)

func NewUpstreamsFromObj

func NewUpstreamsFromObj(in interface{}) ([]*Upstream, error)

func NewUpstreamsFromUrls

func NewUpstreamsFromUrls(hosts []string) ([]*Upstream, error)

func (*Upstream) String

func (u *Upstream) String() string

Jump to

Keyboard shortcuts

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