router

package
v0.0.0-...-84d4900 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2019 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultRouter = "_def_"

DefaultRouter is the name of the default route for the router.

Variables

View Source
var BodyLimitSize int64 = 1048576

BodyLimitSize is the max request body size.

View Source
var HTTPClient *http.Client

HTTPClient is the default client to contact the server.

Functions

func Adaptor

func Adaptor(handler http.Handler) http.HandlerFunc

Adaptor is used for plug a http.Handler with a http.HandlerFunc.

func Balance

Balance is the handler that inserts in the context the next ip address.

func CircuitBrake

func CircuitBrake(cbs Cbs, handler responsewriter.HandlerFunc) responsewriter.HandlerFunc

CircuitBrake brakes the connection from the proxy to the server if the server dies.

func ConfigProxyHTTPClient

func ConfigProxyHTTPClient(ca string, insecure bool) error

ConfigProxyHTTPClient configure one client with specific ca and insecure flag.

func NewRedirHostRouter

func NewRedirHostRouter(dst string) (r *httprouter.Router)

NewRedirHostRouter is a router that redirect to another host the request.

func NewStaticRouter

func NewStaticRouter(prefix, dir string, fs afero.Fs, expTime time.Duration, rc *request.Config, formsizefile int64, cs *cache.Storage) (router *httprouter.Router)

NewStaticRouter is a fileserver for a static dir.

func Proxy

func Proxy(path string, timeout time.Duration) responsewriter.HandlerFunc

Proxy forward the requests coming on path to dst url.

func RedirHost

func RedirHost(root, dst string) http.HandlerFunc

RedirHost redirect from one host to another without modify the other parameters of the url.

func Retry

Retry try multiple time to get a correct response from the handler.

func WithSignal

func WithSignal(ctx context.Context, s ...os.Signal) (context.Context, context.CancelFunc)

Types

type Cbs

Cbs stores the servers subject of the circuit braker

type HostSwitch

type HostSwitch map[string]http.Handler

HostSwitch selects the router associated with one hostname.

func (HostSwitch) ServeHTTP

func (hs HostSwitch) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP satisfy the interface for http package.

func (HostSwitch) Set

func (hs HostSwitch) Set(domain string, router http.Handler)

Set store a new router for that domain or overwrite the router for the domain.

type LoadBalance

type LoadBalance interface {
	AddAddrs(method, path, ip string)
	Next(method, path string) string
	Remove(method, path, ip string)
}

LoadBalance interface reuni the methods for a load balancing.

func NewRedirDst

func NewRedirDst(dst string) LoadBalance

NewRedirDst creates a balancer with a single address.

type Op

type Op string

Op is a operation in the router.

const (
	//RouteOpAdd is a op of type add.
	RouteOpAdd Op = "add"
	//RouteOpDel is a op of type del.
	RouteOpDel Op = "delete"
	//RouteOpGet is a op of type get.
	RouteOpGet Op = "get"
)

type OpErr

type OpErr struct {
	Err string `json:"err"`
	Op  string `json:"op"`
}

OpErr handle the error to the client.

func (*OpErr) Error

func (oe *OpErr) Error() string

type RedirDst

type RedirDst struct {
	// contains filtered or unexported fields
}

RedirDst redirects the resquest to a single address.

func (*RedirDst) AddAddrs

func (rd *RedirDst) AddAddrs(method, path, ip string)

AddAddrs do nothing

func (*RedirDst) Next

func (rd *RedirDst) Next(method, path string) string

Next return always the same address

func (*RedirDst) Remove

func (rd *RedirDst) Remove(method, path, ip string)

Remove do nothing

type Response

type Response struct {
	Methode string `json:"methode"`
	Router  string `json:"router"`
	Path    string `json:"path"`
	Err     string `json:"err"`
	Op      string `json:"op"`
}

Response is the response sent to the client

func (*Response) Error

func (r *Response) Error() string

type ResponseRoutes

type ResponseRoutes struct {
	Router string `json:"router"`
	Err    string `json:"err"`
	Op     string `json:"op"`
	Routes Routes `json:"routes"`
}

func (*ResponseRoutes) Error

func (r *ResponseRoutes) Error() string

type RoundRobin

type RoundRobin struct {
	// contains filtered or unexported fields
}

RoundRobin make a rounding robin list of ip addresses of destinies.

func NewRoundRobin

func NewRoundRobin() *RoundRobin

NewRoundRobin creates a new rounding roubing list.

func (*RoundRobin) AddAddrs

func (rr *RoundRobin) AddAddrs(method, path, ip string)

AddAddrs adds an ip to the list.

func (*RoundRobin) Next

func (rr *RoundRobin) Next(method, path string) string

Next pops the next address from the list.

func (*RoundRobin) Remove

func (rr *RoundRobin) Remove(method, path, target string)

Remove exclude a ip from the list of proxies

type Route

type Route struct {
	Methode string
	Router  string
	Path    string
	RedirTo string
}

Route define one route.

type Router

type Router struct {
	// contains filtered or unexported fields
}

Router implements a router for http requests received in a build in http server.

func (*Router) Add

func (r *Router) Add(routerName, method, path, dst string) (err error)

Add a new handler to domain. If routerName doesn't exist add route to the default router.

func (*Router) AddRoute

func (r *Router) AddRoute(routerName, method, path string, handler http.HandlerFunc)

AddRoute adds a new route to the router. If routerName doesn't exist add route to the default router.

func (*Router) Get

func (r *Router) Get(routerName string) (rs Routes, err error)

func (*Router) HTTPHandlers

func (r *Router) HTTPHandlers(f func(first http.Handler) http.Handler)

HTTPHandlers plugs toggeder the handlers.

func (*Router) Middlewares

func (r *Router) Middlewares(f func(last responsewriter.HandlerFunc) responsewriter.HandlerFunc)

Middlewares sets the chain of middlers used by the router handlers. Parameter last must be part of the chain and must be the last middleware.

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request)

ServeHTTP satisfy the interface for this work like a http server.

func (*Router) SetHTTPAddr

func (r *Router) SetHTTPAddr(addr string)

SetHTTPAddr sets the default route for the adderess of the http server.

func (*Router) SetHTTPSAddr

func (r *Router) SetHTTPSAddr(addr string)

SetHTTPSAddr sets the default route for the adderess of the https server.

func (*Router) SetHostSwitch

func (r *Router) SetHostSwitch(domain, routername string) error

SetHostSwitch sets the router to one hostname.

func (*Router) Start

func (r *Router) Start(routers Routers, lb LoadBalance, to time.Duration, proxyRetries int) error

Start listners

func (*Router) Stop

func (r *Router) Stop() error

Stop halts the router and close the listners.

type Routers

type Routers map[string]*httprouter.Router

Routers are the named routers avaliable.

func NewRouters

func NewRouters() Routers

NewRouters creates a new group of routers

func (Routers) Del

func (r Routers) Del(name string)

Del remove a router.

func (Routers) Get

func (r Routers) Get(name string) *httprouter.Router

Get get a named route or if it doesn't exist get the default one.

func (Routers) Set

func (r Routers) Set(name string, router *httprouter.Router)

Set add a new router with name to the group. If called again with the same name it will replace that router.

type Routes

type Routes []*Route

Routes describe a group of routes.

func (Routes) Len

func (r Routes) Len() int

func (Routes) Less

func (r Routes) Less(i, j int) bool

func (Routes) Search

func (rs Routes) Search(path string) bool

func (Routes) Swap

func (r Routes) Swap(i, j int)

Jump to

Keyboard shortcuts

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