Documentation ¶
Index ¶
Constants ¶
View Source
const ( // HealthCheckInterval 健康检查的周期 HealthCheckInterval = time.Second * 10 // HealthCheckTimeout 健康检查的超时时间 HealthCheckTimeout = time.Second * 3 )
Variables ¶
View Source
var ( HaveNotBeenStartedError = errorKit.Newf("have not been started") AlreadyStartedError = errorKit.Newf("already started") AlreadyDisposedError = errorKit.Newf("already disposed") NoAccessBackendError = errorKit.Newf("no access backend") NoBackendAddedError = errorKit.Newf("no backend added") )
Functions ¶
This section is empty.
Types ¶
type Backend ¶
Backend 后端节点.
func NewBackend ¶
func (*Backend) HandleRequest ¶
func (*Backend) HealthCheck ¶
func (be *Backend) HealthCheck()
HealthCheck 健康检查(此方法会修改 alive 字段).
@return 后端服务是否可用?
type LoadBalancer ¶
LoadBalancer 负载均衡器.
!!!: 创建实例后,需要先调用 Start.
func NewLoadBalancer ¶
func NewLoadBalancer(logger *zap.Logger) (lb *LoadBalancer)
NewLoadBalancer
PS: 返回的*LoadBalancer实例,需要手动调用 Start 以启动.
@param logger 可以为nil,默认输出到控制台
func (*LoadBalancer) AddBackend ¶
func (lb *LoadBalancer) AddBackend(be *Backend) (err error)
func (*LoadBalancer) HandleRequest ¶
func (lb *LoadBalancer) HandleRequest(w http.ResponseWriter, r *http.Request) (err error)
Click to show internal directories.
Click to hide internal directories.