Documentation
¶
Index ¶
- type Client
- type Conn
- func (c *Conn) Bind(uid int64)
- func (c *Conn) Close() error
- func (c *Conn) DelAttr(key any)
- func (c *Conn) GetAttr(key any) value.Value
- func (c *Conn) ID() int64
- func (c *Conn) LocalAddr() (net.Addr, error)
- func (c *Conn) LocalIP() (string, error)
- func (c *Conn) Push(message *cluster.Message) error
- func (c *Conn) RemoteAddr() (net.Addr, error)
- func (c *Conn) RemoteIP() (string, error)
- func (c *Conn) SetAttr(key, value any)
- func (c *Conn) UID() int64
- func (c *Conn) Unbind()
- type Context
- type DialOption
- type EventHandler
- type HookHandler
- type Option
- type Proxy
- func (p *Proxy) AddEventListener(event cluster.Event, handler EventHandler)
- func (p *Proxy) AddHookListener(hook cluster.Hook, handler HookHandler)
- func (p *Proxy) AddRouteHandler(route int32, handler RouteHandler)
- func (p *Proxy) Client() network.Client
- func (p *Proxy) Dial(opts ...DialOption) (*Conn, error)
- func (p *Proxy) ID() string
- func (p *Proxy) Name() string
- func (p *Proxy) SetDefaultRouteHandler(handler RouteHandler)
- type RouteHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client is the client component.
It dials connections to the server and provides registration of routes, events and hooks as well as message sending and receiving.
func (*Client) Destroy ¶
func (c *Client) Destroy()
Destroy destroys the client.
It marks the client as shut, closes every connection and triggers the Destroy hook.
type Conn ¶ added in v2.1.0
type Conn struct {
// contains filtered or unexported fields
}
Conn wraps a network connection.
It exposes message pushing, attribute management and basic information querying on top of the underlying network connection.
func (*Conn) LocalAddr ¶ added in v2.1.0
LocalAddr returns the local address, or an error when it cannot be determined.
func (*Conn) LocalIP ¶ added in v2.1.0
LocalIP returns the local IP address, or an error when it cannot be determined.
func (*Conn) Push ¶ added in v2.1.0
Push pushes message to the server after encoding and encrypting its data.
func (*Conn) RemoteAddr ¶ added in v2.1.0
RemoteAddr returns the remote address, or an error when it cannot be determined.
func (*Conn) RemoteIP ¶ added in v2.1.0
RemoteIP returns the remote IP address, or an error when it cannot be determined.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is the route context.
It carries the connection and message information used by route handlers.
func (*Context) Data ¶
Data returns the message data.
It returns the raw, undecrypted message content; use Context.Parse when the plaintext is needed.
type DialOption ¶ added in v2.1.0
type DialOption func(o *dialOptions)
DialOption is a dial option.
func WithConnAttr ¶ added in v2.1.0
func WithConnAttr(key string, value any) DialOption
WithConnAttr sets a connection attribute.
func WithDialAddr ¶ added in v2.1.0
func WithDialAddr(addr string) DialOption
WithDialAddr sets the dial address.
type EventHandler ¶
type EventHandler func(conn *Conn)
EventHandler is the event handler of the client.
type HookHandler ¶ added in v2.1.0
type HookHandler func(proxy *Proxy)
HookHandler is the hook handler of the client.
type Option ¶
type Option func(o *options)
Option is a client option.
func WithEncryptor ¶
WithEncryptor sets the message encryptor.
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy is the client proxy.
It exposes the registration of routes, events and hooks as well as dialing.
func (*Proxy) AddEventListener ¶
func (p *Proxy) AddEventListener(event cluster.Event, handler EventHandler)
AddEventListener adds an event listener for the given event.
func (*Proxy) AddHookListener ¶ added in v2.1.0
func (p *Proxy) AddHookListener(hook cluster.Hook, handler HookHandler)
AddHookListener adds a hook listener for the given hook.
func (*Proxy) AddRouteHandler ¶
func (p *Proxy) AddRouteHandler(route int32, handler RouteHandler)
AddRouteHandler adds a route handler for the given route.
func (*Proxy) Dial ¶ added in v2.1.0
func (p *Proxy) Dial(opts ...DialOption) (*Conn, error)
Dial dials a connection to the server and returns the wrapped connection.
func (*Proxy) SetDefaultRouteHandler ¶
func (p *Proxy) SetDefaultRouteHandler(handler RouteHandler)
SetDefaultRouteHandler sets the default route handler that serves every unregistered route.
type RouteHandler ¶
type RouteHandler func(ctx *Context)
RouteHandler is the route handler of the client.