Documentation ¶
Index ¶
- Constants
- func PutNotifierKey(ctx context.Context, n *Notifier) context.Context
- type HttpConfig
- type HttpServer
- type ID
- type Middleware
- type Notifier
- type Resolver
- type RpcContext
- type RpcHandler
- type RpcServer
- func (r *RpcServer) Close()
- func (r *RpcServer) CloseWsConn(wsCtx *WebSocketContext)
- func (r *RpcServer) RegisterEndpoints(nameSpace string, sh any) error
- func (r *RpcServer) RegisterEvents(nameSpace string, sh any) error
- func (r *RpcServer) ResolveHttp(ctx *context.Context, rpcMessage []byte) []byte
- func (r *RpcServer) ResolveWs(ctx *context.Context, wsCtx *WebSocketContext, rpcMessage []byte) []byte
- func (r *RpcServer) Run(ctx context.Context) error
- func (r *RpcServer) WithMiddleware(m Middleware)
- type ServiceMap
- type Subscription
- type Transport
- type TransportOption
- type WebSocketContext
Constants ¶
const (
DefaultContentType = "application/json"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HttpConfig ¶
type HttpConfig struct { HttpEndpoint string HttpPathPrefix string HttpCors []string HttpCompress bool HttpTimeout time.Duration WsEndpoint string WsPathPrefix string WsHandshakeTimeout time.Duration WsOnly bool }
HttpConfig holds both http and websocket configuration elements
type HttpServer ¶
type HttpServer struct { Logger *log.Logger Config HttpConfig // contains filtered or unexported fields }
type ID ¶
type ID string
ID defines a pseudo random number that is used to identify RPC subscriptions.
type Middleware ¶
type Middleware func(handler RpcHandler) RpcHandler
type Notifier ¶
type Notifier struct {
// contains filtered or unexported fields
}
Notifier is tied to a RPC connection that supports subscriptions. Server callbacks use the notifier to send notifications.
func NotifierFromContext ¶
NotifierFromContext returns the Notifier value stored in ctx, if any.
func (*Notifier) CreateSubscription ¶
func (n *Notifier) CreateSubscription() *Subscription
CreateSubscription returns a new subscription that is coupled to the RPC connection
type Resolver ¶
type Resolver interface { ResolveHttp(ctx *context.Context, rpcMessage []byte) []byte ResolveWs(ctx *context.Context, wsCtx *WebSocketContext, rpcMessage []byte) []byte CloseWsConn(wsCtx *WebSocketContext) }
type RpcContext ¶
type RpcContext struct {
// contains filtered or unexported fields
}
func (*RpcContext) GetBody ¶
func (ctx *RpcContext) GetBody() []byte
GetBody returns the body as a byte slice
func (*RpcContext) GetMethod ¶
func (ctx *RpcContext) GetMethod() string
GetMethod returns the method name
func (*RpcContext) SetErrorObject ¶
func (ctx *RpcContext) SetErrorObject(e errs.Error) *RpcContext
SetErrorObject sets response as error using the provided error object
func (*RpcContext) SetResponse ¶
func (ctx *RpcContext) SetResponse(response []byte) *RpcContext
SetResponse sets whole response using the provided byte slice
type RpcHandler ¶
type RpcHandler func(ctx *context.Context, rpcCtx *RpcContext) *RpcContext
type RpcServer ¶
type RpcServer struct {
// contains filtered or unexported fields
}
func (*RpcServer) CloseWsConn ¶
func (r *RpcServer) CloseWsConn(wsCtx *WebSocketContext)
func (*RpcServer) RegisterEndpoints ¶
RegisterEndpoints creates a map of service handlers for the given receiver by adding its exposed methods and their arguments
func (*RpcServer) RegisterEvents ¶
RegisterEvents creates a map of subscription handlers for the given receiver by adding its exposed methods and their arguments
func (*RpcServer) ResolveHttp ¶
func (*RpcServer) WithMiddleware ¶
func (r *RpcServer) WithMiddleware(m Middleware)
WithMiddleware places the given handler function to the middlewares chain.
type ServiceMap ¶
type ServiceMap struct {
// contains filtered or unexported fields
}
ServiceMap holds all the services and subscriptions
type Subscription ¶
type Subscription struct { ID ID // contains filtered or unexported fields }
A Subscription is created by a notifier and tied to that notifier. The client can use this subscription to wait for an unsubscribe request for the client, see Err().
func (*Subscription) Err ¶
func (s *Subscription) Err() <-chan error
Err returns a channel that is closed when the client send an unsubscribe request.
type TransportOption ¶
type TransportOption func(s *RpcServer)
func WithTransport ¶
func WithTransport(transport Transport) TransportOption
type WebSocketContext ¶
type WebSocketContext struct {
// contains filtered or unexported fields
}