websocket_server

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ErrorCode_InvalidRequest                       RPCErrorCode = 1000
	ErrorCode_NotFound                                          = 2000
	ErrorCode_InvalidParams                                     = 3000
	ErrorCode_InvalidParams_Invalid_Arguments                   = 3001
	ErrorCode_InvalidParams_Insufficient_Arguments              = 3002
	ErrorCode_InternalError                                     = 4000
	ErrorCode_ServerError                                       = 5000
)
View Source
const RequestQueueSize = 32

Variables

View Source
var (
	ErrAdapterNotImplemented = errors.New("adapter: not implemented")
)
View Source
var (
	ErrBackendNotImplemented = errors.New("backend: not implemented")
)
View Source
var (
	ErrConnectionClosed = errors.New("client: conn closed")
)
View Source
var (
	ErrMethodNotFound = errors.New("rpc: method not found")
)

Functions

func Module

func Module(scope string) fx.Option

Types

type Adapter

type Adapter interface {
	HandleMessage(Client) error
	PrepareNotification(eventName string, payload interface{}) ([]byte, error)
	PrepareResponse(*RPCResponse) ([]byte, error)
	Register(method string, fn RPCFunc) error
	Unregister(method string)
}

func NewAdapter

func NewAdapter() Adapter

type Backend

type Backend interface {
	ParseRequest(r io.Reader) (*RPCRequest, error)
	PrepareNotification(eventName string, payload interface{}) ([]byte, error)
	PrepareResponse(*RPCResponse) ([]byte, error)
}

func NewBackend

func NewBackend() Backend

type Client

type Client interface {
	GetOptions() *Options
	GetConnection() net.Conn
	GetClientID() uuid.UUID
	GetMeta() *Metadata
	GetReader() io.Reader
	Send(data []byte) error
	Respond(res *RPCResponse) error
	Notify(eventName string, payload interface{}) error
	Resume() error
	CreateRunner(func(*Runner)) *Runner
	Release()
	Close()
}

func NewClient

func NewClient(options *Options, conn net.Conn) Client

type ClientManager

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

func NewClientManager

func NewClientManager() *ClientManager

func (*ClientManager) Close

func (clientMgr *ClientManager) Close()

func (*ClientManager) Register

func (clientMgr *ClientManager) Register(c Client)

func (*ClientManager) Run

func (clientMgr *ClientManager) Run()

func (*ClientManager) Unregister

func (clientMgr *ClientManager) Unregister(c Client)

type Context

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

func NewContext

func NewContext(client Client, req *RPCRequest) *Context

func (*Context) Error

func (ctx *Context) Error(code RPCErrorCode, data string) error

func (*Context) GetClient

func (ctx *Context) GetClient() Client

func (*Context) GetMeta

func (ctx *Context) GetMeta() *Metadata

func (*Context) GetReader

func (ctx *Context) GetReader() io.Reader

func (*Context) GetRequest

func (ctx *Context) GetRequest() *RPCRequest

func (*Context) Notify

func (ctx *Context) Notify(eventName string, payload interface{}) error

func (*Context) Respond

func (ctx *Context) Respond(res *RPCResponse) error

func (*Context) Send

func (ctx *Context) Send(data []byte) error

type Endpoint

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

func NewEndpoint

func NewEndpoint(uri string, options *Options) *Endpoint

func (*Endpoint) Establish

func (ep *Endpoint) Establish(c *gin.Context)

func (*Endpoint) GetAdapter added in v0.0.4

func (ep *Endpoint) GetAdapter() Adapter

func (*Endpoint) GetUri

func (ep *Endpoint) GetUri() string

type Metadata

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

func NewMetadata

func NewMetadata() *Metadata

func (*Metadata) Delete

func (md *Metadata) Delete(key string)

func (*Metadata) Get

func (md *Metadata) Get(key string) interface{}

func (*Metadata) GetInt

func (md *Metadata) GetInt(key string) int

func (*Metadata) GetString

func (md *Metadata) GetString(key string) string

func (*Metadata) Set

func (md *Metadata) Set(key string, value interface{})

type Options

type Options struct {
	Adapter        Adapter
	MaxClients     int
	OnConnected    func(Client) error
	OnDisconnected func(Client) error
	OnMessage      func(Client) error
}

func NewOptions

func NewOptions() *Options

type Packet

type Packet struct {
	Length  int
	Payload []byte
}

type Params

type Params struct {
	fx.In

	Lifecycle  fx.Lifecycle
	Logger     *zap.Logger
	HTTPServer *http_server.HTTPServer
}

type PollerPool

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

func NewPollerPool

func NewPollerPool() *PollerPool

func (*PollerPool) Add

func (pp *PollerPool) Add(c Client) error

func (*PollerPool) Remove

func (pp *PollerPool) Remove(c Client) error

func (*PollerPool) Wait

func (pp *PollerPool) Wait(fn func([]Client))

type RPCAdapter

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

func NewRPCAdapter

func NewRPCAdapter(opts ...RPCAdapterOpt) *RPCAdapter

func (*RPCAdapter) HandleMessage

func (ra *RPCAdapter) HandleMessage(c Client) error

func (*RPCAdapter) PrepareNotification

func (ra *RPCAdapter) PrepareNotification(eventName string, payload interface{}) ([]byte, error)

func (*RPCAdapter) PrepareResponse

func (ra *RPCAdapter) PrepareResponse(res *RPCResponse) ([]byte, error)

func (*RPCAdapter) Register

func (ra *RPCAdapter) Register(method string, fn RPCFunc) error

func (*RPCAdapter) Unregister

func (ra *RPCAdapter) Unregister(method string)

type RPCAdapterOpt

type RPCAdapterOpt func(*RPCAdapter)

func WithRPCBackend

func WithRPCBackend(b Backend) RPCAdapterOpt

type RPCError

type RPCError struct {
	Code    RPCErrorCode `json:"code"`
	Message string       `json:"message"`
	Data    interface{}  `json:"data,omitempty"`
}

func NewError

func NewError(code RPCErrorCode, data interface{}) *RPCError

func (*RPCError) Error

func (e *RPCError) Error() string

type RPCErrorCode

type RPCErrorCode int32

type RPCFunc

type RPCFunc func(*Context) (interface{}, error)

type RPCRequest

type RPCRequest struct {
	ID     int64
	Method string
	Params interface{}
}

type RPCResponse

type RPCResponse struct {
	ID     int64
	Error  error
	Result interface{}
}

type RequestHandler

type RequestHandler func(*Context) error

type RequestQueue

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

func NewRequestQueue

func NewRequestQueue() *RequestQueue

func (*RequestQueue) Consume

func (rq *RequestQueue) Consume(fn RequestHandler) error

func (*RequestQueue) Push

func (rq *RequestQueue) Push(c *Context)

type RequestTask

type RequestTask struct {
	Ctx *Context
}

type Runner

type Runner struct {
	IsRunning bool
	// contains filtered or unexported fields
}

func NewRunner

func NewRunner(fn RunnerFunc) *Runner

func (*Runner) Start

func (r *Runner) Start()

func (*Runner) Stop

func (r *Runner) Stop()

func (*Runner) WaitForClose

func (r *Runner) WaitForClose()

type RunnerFunc

type RunnerFunc func(*Runner)

type WebSocketServer

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

func (*WebSocketServer) CreateEndpoint

func (wss *WebSocketServer) CreateEndpoint(uri string, opts *Options) (*Endpoint, error)

func (*WebSocketServer) GetEndpoint added in v0.0.4

func (wss *WebSocketServer) GetEndpoint(uri string) *Endpoint

func (*WebSocketServer) RemoveEndpoint

func (wss *WebSocketServer) RemoveEndpoint(ep *Endpoint) error

Jump to

Keyboard shortcuts

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