slbKit

package
v3.1.101 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

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

type Backend struct {
	mutexKit.Mutex
	// contains filtered or unexported fields
}

Backend 后端节点.

func NewBackend

func NewBackend(urlStr string) (*Backend, error)

func (*Backend) Disable

func (be *Backend) Disable(reason string, a ...any)

func (*Backend) Enable

func (be *Backend) Enable(reason string, a ...any)

func (*Backend) HandleRequest

func (be *Backend) HandleRequest(w http.ResponseWriter, r *http.Request) error

func (*Backend) HealthCheck

func (be *Backend) HealthCheck()

HealthCheck 健康检查(此方法会修改 alive 字段).

@return 后端服务是否可用?

func (*Backend) IsAlive

func (be *Backend) IsAlive() (alive bool)

func (*Backend) String

func (be *Backend) String() string

type LoadBalancer

type LoadBalancer struct {
	*mutexKit.RWMutex
	// contains filtered or unexported fields
}

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) Dispose

func (lb *LoadBalancer) Dispose()

Dispose 手动中止.

func (*LoadBalancer) HandleRequest

func (lb *LoadBalancer) HandleRequest(w http.ResponseWriter, r *http.Request) (err error)

func (*LoadBalancer) Start

func (lb *LoadBalancer) Start() error

Start 手动启动.

type Status

type Status string
const (
	StatusInitialized Status = "initialized"

	StatusStarted Status = "started"

	StatusDisposed Status = "disposed"
)

Jump to

Keyboard shortcuts

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