Documentation ¶
Index ¶
- Constants
- Variables
- type DefaultRouter
- func (r *DefaultRouter) Add(p string, proxy *HTTPProxy)
- func (r *DefaultRouter) HasPrefix(p string) bool
- func (r *DefaultRouter) Remove(p string)
- func (r *DefaultRouter) Route(w http.ResponseWriter, req *http.Request) (*HTTPProxy, string)
- func (r *DefaultRouter) ServeHTTP(w http.ResponseWriter, req *http.Request)
- type HTTPProxy
- func (httpProxy *HTTPProxy) ChangeLb(mode string) error
- func (h *HTTPProxy) HealthCheck()
- func (h *HTTPProxy) ReadAlive(url string) bool
- func (h *HTTPProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (h *HTTPProxy) SetAlive(url string, alive bool)
- func (httpProxy *HTTPProxy) SetRateLimiter(info LimiterInfo) error
- type Info
- type LimiterInfo
- type ProxyMap
- func (proxyMap *ProxyMap) AddProxy(pattern string, host string) error
- func (proxyMap *ProxyMap) AddProxyWithLocation(l config.Location) error
- func (proxyMap *ProxyMap) AddRelations(pattern string, proxy *HTTPProxy, location config.Location)
- func (proxyMap *ProxyMap) Marshal() ([]byte, error)
- func (proxyMap *ProxyMap) RemoveHost(pattern string, host string) error
- func (proxyMap *ProxyMap) RemoveProxy(pattern string) error
- func (proxyMap *ProxyMap) UnMarshal(serialized io.ReadCloser) error
- type Router
Constants ¶
View Source
const ( XRealIP string = "X-Real-IP" XProxy string = "X-Proxy" ReverseProxy string = "Balancer-Reverse-Proxy" )
Variables ¶
View Source
var HealthCheckTimeout = 5 * time.Second
Functions ¶
This section is empty.
Types ¶
type DefaultRouter ¶
使用哈希记录路由前缀
func (*DefaultRouter) Add ¶
func (r *DefaultRouter) Add(p string, proxy *HTTPProxy)
func (*DefaultRouter) HasPrefix ¶
func (r *DefaultRouter) HasPrefix(p string) bool
func (*DefaultRouter) Remove ¶
func (r *DefaultRouter) Remove(p string)
func (*DefaultRouter) Route ¶
func (r *DefaultRouter) Route(w http.ResponseWriter, req *http.Request) (*HTTPProxy, string)
具体路由选择的算法
func (*DefaultRouter) ServeHTTP ¶
func (r *DefaultRouter) ServeHTTP(w http.ResponseWriter, req *http.Request)
执行方法的顺序: 1. 判断 ip 是否在黑名单内 (acl) 2. 执行一遍 FilterChain 的方法 3. 根据 path 找到反向代理 4. 限流 5. 根据反向代理中的主机路径,进行负载均衡 6. 找出一个转发的主机,转发请求
type HTTPProxy ¶
type HTTPProxy struct { HostMap map[string]*httputil.ReverseProxy Pattern string Lb balancer.Balancer Alive map[string]bool Methods map[string]ratelimit.RateLimiter HostsShutDown map[string]chan bool ShutDown chan bool ProxyMap *ProxyMap sync.RWMutex }
* * hostMap: 主机对反向代理的映射,其中的键值表示我们需要反向代理的主机 * lb: 负载均衡器 * alive: 反向代理的主机是否处于健康状态
func NewHTTPProxy ¶
func NewHTTPProxy(pattern string, targetHosts []string, algo balancer.Algorithm) (*HTTPProxy, error)
对每一个 URL 创建反向代理并且记录到 URL 树中
func (*HTTPProxy) HealthCheck ¶
func (h *HTTPProxy) HealthCheck()
func (*HTTPProxy) SetRateLimiter ¶
func (httpProxy *HTTPProxy) SetRateLimiter(info LimiterInfo) error
type LimiterInfo ¶
type ProxyMap ¶
type ProxyMap struct { sync.RWMutex Relations map[string]*HTTPProxy `json:"-"` Locations map[string]config.Location Limiters map[string][]LimiterInfo Infos Info }
func NewProxyMap ¶
func NewProxyMap() *ProxyMap
func (*ProxyMap) AddProxyWithLocation ¶
func (*ProxyMap) AddRelations ¶
func (*ProxyMap) RemoveHost ¶
func (*ProxyMap) RemoveProxy ¶
Click to show internal directories.
Click to hide internal directories.