Documentation
¶
Index ¶
- Constants
- Variables
- func Adaptor(handler http.Handler) http.HandlerFunc
- func Balance(lb LoadBalance, handler responsewriter.HandlerFunc) responsewriter.HandlerFunc
- func CircuitBrake(cbs Cbs, handler responsewriter.HandlerFunc) responsewriter.HandlerFunc
- func ConfigProxyHTTPClient(ca string, insecure bool) error
- func IPBlock(deny list.List, handler responsewriter.HandlerFunc) responsewriter.HandlerFunc
- func NewRedirHostRouter(dst string) (r *httprouter.Router)
- func NewStaticRouter(prefix, dir string, fs afero.Fs, expTime time.Duration, rc *request.Config, ...) (router *httprouter.Router)
- func Proxy(path string, timeout time.Duration) responsewriter.HandlerFunc
- func RedirHost(root, dst string) http.HandlerFunc
- func Retry(times int, handler responsewriter.HandlerFunc) responsewriter.HandlerFunc
- func WithSignal(ctx context.Context, s ...os.Signal) (context.Context, context.CancelFunc)
- type Cbs
- type HostSwitch
- type LoadBalance
- type Op
- type OpErr
- type RedirDst
- type Response
- type ResponseRoutes
- type RoundRobin
- type Route
- type Router
- func (r *Router) Add(routerName, method, path, dst string) (err error)
- func (r *Router) AddRoute(routerName, method, path string, handler http.HandlerFunc)
- func (r *Router) Get(routerName string) (rs Routes, err error)
- func (r *Router) HTTPHandlers(f func(first http.Handler) http.Handler)
- func (r *Router) Middlewares(f func(last responsewriter.HandlerFunc) responsewriter.HandlerFunc)
- func (r *Router) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (r *Router) SetHTTPAddr(addr string)
- func (r *Router) SetHTTPSAddr(addr string)
- func (r *Router) SetHostSwitch(domain, routername string) error
- func (r *Router) Start(routers Routers, lb LoadBalance, to time.Duration, proxyRetries int) error
- func (r *Router) Stop() error
- type Routers
- type Routes
Constants ¶
const DefaultRouter = "_def_"
DefaultRouter is the name of the default route for the router.
Variables ¶
var BodyLimitSize int64 = 1048576
BodyLimitSize is the max request body size.
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 ¶
func Balance(lb LoadBalance, handler responsewriter.HandlerFunc) responsewriter.HandlerFunc
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 ¶
ConfigProxyHTTPClient configure one client with specific ca and insecure flag.
func IPBlock ¶
func IPBlock(deny list.List, handler responsewriter.HandlerFunc) responsewriter.HandlerFunc
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 ¶
func Retry(times int, handler responsewriter.HandlerFunc) responsewriter.HandlerFunc
Retry try multiple time to get a correct response from the handler.
func WithSignal ¶
Types ¶
type Cbs ¶
type Cbs map[string]*gobreaker.CircuitBreaker
Cbs stores the servers subject of the circuit braker
type HostSwitch ¶
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.
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 RedirDst ¶
type RedirDst struct {
// contains filtered or unexported fields
}
RedirDst redirects the resquest to a single address.
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
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 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 ¶
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) HTTPHandlers ¶
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 ¶
SetHTTPAddr sets the default route for the adderess of the http server.
func (*Router) SetHTTPSAddr ¶
SetHTTPSAddr sets the default route for the adderess of the https server.
func (*Router) SetHostSwitch ¶
SetHostSwitch sets the router to one hostname.