Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotEnoughBackends = fmt.Errorf("load balancer requires at least 2 backends")
Functions ¶
This section is empty.
Types ¶
type HTTPBackend ¶
type HTTPBackend struct {
// contains filtered or unexported fields
}
HTTPBackend represents an HTTP backend for handling requests.
func NewBackend ¶
func NewBackend(factory RequestFactory, options ...HTTPBackendOption) *HTTPBackend
NewBackend creates a new instance of HTTPBackend with the given RequestFactory.
func (*HTTPBackend) Handle ¶
func (b *HTTPBackend) Handle(conn wasabi.Connection, r wasabi.Request) error
Handle handles the incoming request by sending it to the HTTP server and returning the response. It takes a connection and a request as parameters and returns an error if any.
type HTTPBackendOption ¶
type HTTPBackendOption func(*httpBackendConfig)
func WithMaxRequestsPerHost ¶ added in v0.4.0
func WithMaxRequestsPerHost(maxReqPerHost int) HTTPBackendOption
WithMaxRequestsPerHost sets the maximum number of requests per host.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) HTTPBackendOption
WithTimeout sets the default timeout for the HTTP client.
type LoadBalancer ¶ added in v0.5.0
type LoadBalancer struct {
// contains filtered or unexported fields
}
func NewLoadBalancer ¶ added in v0.5.0
func NewLoadBalancer(backends []struct { Handler wasabi.RequestHandler Weight int32 }) (*LoadBalancer, error)
NewLoadBalancer creates a new instance of LoadBalancer with the given backends. It takes a slice of struct containing two fields
`Handler` the `wasabi.RequestHandler` `Weight` the load factor of this handler. The more the weight, the higher load can the handler server
Note: handlers with zero weight will be ignored and will be not considered for load balancing
func (*LoadBalancer) Handle ¶ added in v0.5.0
func (lb *LoadBalancer) Handle(conn wasabi.Connection, r wasabi.Request) error
Handle handles the incoming request by sending it to the least busy backend and returning the response. It takes a connection and a request as parameters and returns an error if any.
type LoadBalancerNode ¶ added in v0.5.0
type LoadBalancerNode struct {
// contains filtered or unexported fields
}
type OnRequestCallback ¶ added in v0.3.0
OnRequestCallback is a function type that represents a callback function for handling requests in the queue. It takes three parameters:
- conn: a `wasabi.Connection` object representing the connection.
- req: a `wasabi.Request` object representing the request.
- id: a string representing the ID of the request.
It returns an error if there was an issue handling the request.
type QueueBackend ¶ added in v0.3.0
type QueueBackend struct {
// contains filtered or unexported fields
}
QueueBackend represents a backend for handling requests in a queue.
func NewQueueBackend ¶ added in v0.3.0
func NewQueueBackend(onRequest OnRequestCallback) *QueueBackend
NewQueueBackend creates a new instance of QueueBackend. It takes an onRequest callback function as a parameter and returns a pointer to QueueBackend. The onRequest callback function is called when a new request is received and ready to be passed to queue.
func (*QueueBackend) Handle ¶ added in v0.3.0
func (b *QueueBackend) Handle(conn wasabi.Connection, r wasabi.Request) error
Handle handles the incoming request from the given connection. It processes the request, sends the response back to the connection, and returns any error that occurred during the handling process.
func (*QueueBackend) OnResponse ¶ added in v0.3.0
func (b *QueueBackend) OnResponse(id string, msgType websocket.MessageType, data []byte)
OnResponse handles the response received from the server for a specific request. It takes the ID of the request, the message type, and the response data as parameters. If there is a corresponding request channel for the given ID, it sends the response to the channel. If nobody is awaiting for response, it discards the response.
type WSBackend ¶ added in v0.2.0
type WSBackend struct { URL string // contains filtered or unexported fields }
func NewWSBackend ¶ added in v0.2.0
func NewWSBackend(baseURL string, factory WSRequestFactory, opts ...WSBackendOptions) *WSBackend
NewWSBackend creates a new instance of WSBackend with the specified URL.
type WSBackendOptions ¶ added in v0.5.1
type WSBackendOptions func(*WSBackend)
func WithWSDialler ¶ added in v0.5.1
func WithWSDialler(dialer WSDialler) WSBackendOptions
WithWSDialler sets the dialer for the WebSocket backend. It takes a WSDialler function as a parameter and returns a WSBackendOptions function.