gateway

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEndpointAlreadyExists 网关端点已存在
	ErrEndpointAlreadyExists = errors.New("gateway: endpoint already exists")
	// ErrCannotAddRunningEndpoint 无法添加一个正在运行的网关端点
	ErrCannotAddRunningEndpoint = errors.New("gateway: cannot add a running endpoint")
	// ErrEndpointNotExists 该名称下不存在任何端点
	ErrEndpointNotExists = errors.New("gateway: endpoint not exists")
)

Functions

This section is empty.

Types

type Endpoint

type Endpoint struct {
	// contains filtered or unexported fields
}

Endpoint 网关端点

func NewEndpoint

func NewEndpoint(name, address string, options ...EndpointOption) *Endpoint

NewEndpoint 创建网关端点

func (*Endpoint) Connect

func (slf *Endpoint) Connect()

Connect 连接端点

func (*Endpoint) Offline

func (slf *Endpoint) Offline()

Offline 离线

func (*Endpoint) Write

func (slf *Endpoint) Write(packet server.Packet)

Write 写入数据

type EndpointManager

type EndpointManager struct {
	// contains filtered or unexported fields
}

EndpointManager 网关端点管理器

func NewEndpointManager

func NewEndpointManager() *EndpointManager

NewEndpointManager 创建网关端点管理器

func (*EndpointManager) AddEndpoint

func (slf *EndpointManager) AddEndpoint(endpoint *Endpoint) error

AddEndpoint 添加端点

func (*EndpointManager) GetEndpoint

func (slf *EndpointManager) GetEndpoint(name string, conn *server.Conn) (*Endpoint, error)

GetEndpoint 获取端点

func (*EndpointManager) RemoveEndpoint

func (slf *EndpointManager) RemoveEndpoint(endpoint *Endpoint) error

RemoveEndpoint 移除端点

type EndpointOption added in v0.0.30

type EndpointOption func(endpoint *Endpoint)

EndpointOption 网关端点选项

func WithEndpointStateEvaluator added in v0.0.30

func WithEndpointStateEvaluator(evaluator func(costUnixNano float64) float64) EndpointOption

WithEndpointStateEvaluator 设置端点健康值评估函数

type Gateway

type Gateway struct {
	*EndpointManager // 端点管理器
	// contains filtered or unexported fields
}

Gateway 网关

func NewGateway

func NewGateway(srv *server.Server, options ...Option) *Gateway

NewGateway 基于 server.Server 创建网关服务器

func (*Gateway) Run

func (slf *Gateway) Run(addr string) error

Run 运行网关

func (*Gateway) Shutdown

func (slf *Gateway) Shutdown()

Shutdown 关闭网关

type Option

type Option func(gateway *Gateway)

Option 网关选项

func WithEndpointSelector

func WithEndpointSelector(selector func([]*Endpoint) *Endpoint) Option

WithEndpointSelector 设置端点选择器

  • 默认情况下,网关会随机选择一个端点作为目标,如果需要自定义端点选择器,可以通过该选项设置

type Packet

type Packet struct {
	ConnID        string
	WebsocketType int
	Data          []byte
}

Jump to

Keyboard shortcuts

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