threshold

package
Version: v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2014 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package threshold contains predicates that can define various request thresholds

Examples:

* RequestMethod() == "GET" triggers action when request method equals "GET" * IsNetworkError() - triggers action on network errors * RequestMethod() == "GET" && Attempts <= 2 && (IsNetworkError() || ResponseCode() == 408)

This predicate triggers for GET requests with maximum 2 attempts
on network errors or when upstream returns special http response code 408

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Predicate

type Predicate func(request.Request) bool

Predicate that defines what request can fail over in case of error or http response

func AND

func AND(fns ...Predicate) Predicate

AND returns predicate by joining the passed predicates with logical 'and'

func EQ

func EQ(m interface{}, value interface{}) (Predicate, error)

EQ returns predicate that tests for equality of the value of the mapper and the constant

func GE

func GE(m interface{}, value interface{}) (Predicate, error)

GE returns predicate that tests that value of the mapper function is greater than or equal to the constant

func GT

func GT(m interface{}, value interface{}) (Predicate, error)

GT returns predicate that tests that value of the mapper function is greater than the constant

func IsNetworkError

func IsNetworkError() Predicate

IsNetworkError returns a predicate that returns true if last attempt ended with network error.

func LE

func LE(m interface{}, value interface{}) (Predicate, error)

LE returns predicate that tests that value of the mapper function is less than or equal to the constant

func LT

func LT(m interface{}, value interface{}) (Predicate, error)

LT returns predicate that tests that value of the mapper function is less than the constant

func NEQ

func NEQ(m interface{}, value interface{}) (Predicate, error)

NEQ returns predicate that tests for inequality of the value of the mapper and the constant

func NOT

func NOT(p Predicate) Predicate

NOT creates negation of the passed predicate

func OR

func OR(fns ...Predicate) Predicate

OR returns predicate by joining the passed predicates with logical 'or'

func ParseExpression

func ParseExpression(in string) (Predicate, error)

Parses expression in the go language into Failover predicates

type RequestToFloat64

type RequestToFloat64 func(req request.Request) float64

RequestToFloat64 defines mapper function that maps a request to some float64 (e.g extracts some ratio)

type RequestToInt

type RequestToInt func(req request.Request) int

RequestToInt defines mapper function that maps a request to some int (e.g extracts response code)

func Attempts

func Attempts() RequestToInt

Attempts returns mapper of the request to the number of proxy attempts

func ResponseCode

func ResponseCode() RequestToInt

ResponseCode returns mapper of the request to the last response code, returns 0 if there was no response code.

type RequestToString

type RequestToString func(req request.Request) string

RequestToString defines mapper function that maps a request to some string (e.g extracts method name)

func RequestMethod

func RequestMethod() RequestToString

RequestMethod returns mapper of the request to its method e.g. POST

Jump to

Keyboard shortcuts

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