Documentation ¶
Index ¶
- Constants
- func DecodeParams[T any](p RawParams) (T, error)
- func ExtractReverseClient[C any](ctx context.Context) (C, bool)
- func WithClientHandler(ns string, hnd interface{}) func(c *Config)
- func WithClientHandlerAlias(alias, original string) func(c *Config)
- func WithErrors(es Errors) func(c *Config)
- func WithHTTPClient(h *http.Client) func(c *Config)
- func WithNoReconnect() func(c *Config)
- func WithParamEncoder(t interface{}, encoder ParamEncoder) func(c *Config)
- func WithPingInterval(d time.Duration) func(c *Config)
- func WithReconnectBackoff(minDelay, maxDelay time.Duration) func(c *Config)
- func WithTimeout(d time.Duration) func(c *Config)
- type ClientCloser
- func NewClient(ctx context.Context, addr string, namespace string, handler interface{}, ...) (ClientCloser, error)
- func NewCustomClient(namespace string, outs []interface{}, ...) (ClientCloser, error)
- func NewMergeClient(ctx context.Context, addr string, namespace string, outs []interface{}, ...) (ClientCloser, error)
- type Config
- type ConnectionType
- type ErrClient
- type ErrorCode
- type Errors
- type JSONRPCError
- type Option
- type ParamDecoder
- type ParamEncoder
- type RPCConnectionError
- type RPCErrorCodec
- type RPCServer
- type RawParams
- type ServerConfig
- type ServerOption
- func WithMaxRequestSize(max int64) ServerOption
- func WithParamDecoder(t interface{}, decoder ParamDecoder) ServerOption
- func WithReverseClient[RP any](namespace string) ServerOption
- func WithServerErrors(es Errors) ServerOption
- func WithServerPingInterval(d time.Duration) ServerOption
- func WithTracer(l Tracer) ServerOption
- type Tracer
Constants ¶
const ( ProxyTagRetry = "retry" ProxyTagNotify = "notify" ProxyTagRPCMethod = "rpc_method" )
const DEFAULT_MAX_REQUEST_SIZE = 100 << 20 // 100 MiB
Limit request size. Ideally this limit should be specific for each field in the JSON request but as a simple defensive measure we just limit the entire HTTP body. Configured by WithMaxRequestSize.
const FirstUserCode = 2
Variables ¶
This section is empty.
Functions ¶
func DecodeParams ¶
todo is there a better way to tell 'struct with any number of fields'?
func ExtractReverseClient ¶
ExtractReverseClient will extract reverse client from context. Reverse client for the type will only be present if the server was constructed with a matching WithReverseClient option and the connection was a websocket connection. If there is no reverse client, the call will return a zero value and `false`. Otherwise a reverse client and `true` will be returned.
func WithClientHandler ¶
func WithClientHandlerAlias ¶
WithClientHandlerAlias creates an alias for a client HANDLER method - for handlers created with WithClientHandler
func WithErrors ¶
func WithHTTPClient ¶
func WithNoReconnect ¶
func WithNoReconnect() func(c *Config)
func WithParamEncoder ¶
func WithParamEncoder(t interface{}, encoder ParamEncoder) func(c *Config)
func WithReconnectBackoff ¶
func WithTimeout ¶
Types ¶
type ClientCloser ¶
type ClientCloser func()
ClientCloser is used to close Client from further use
func NewClient ¶
func NewClient(ctx context.Context, addr string, namespace string, handler interface{}, requestHeader http.Header) (ClientCloser, error)
NewClient creates new jsonrpc 2.0 client
handler must be pointer to a struct with function fields Returned value closes the client connection TODO: Example
func NewCustomClient ¶
func NewCustomClient(namespace string, outs []interface{}, doRequest func(ctx context.Context, body []byte) (io.ReadCloser, error), opts ...Option) (ClientCloser, error)
NewCustomClient is like NewMergeClient in single-request (http) mode, except it allows for a custom doRequest function
func NewMergeClient ¶
func NewMergeClient(ctx context.Context, addr string, namespace string, outs []interface{}, requestHeader http.Header, opts ...Option) (ClientCloser, error)
NewMergeClient is like NewClient, but allows to specify multiple structs to be filled in the same namespace, using one connection
type ConnectionType ¶
type ConnectionType string
ConnectionType indicates the type of connection, this is set in the context and can be retrieved with GetConnectionType.
const ( // ConnectionTypeUnknown indicates that the connection type cannot be determined, likely because // it hasn't passed through an RPCServer. ConnectionTypeUnknown ConnectionType = "unknown" // ConnectionTypeHTTP indicates that the connection is an HTTP connection. ConnectionTypeHTTP ConnectionType = "http" // ConnectionTypeWS indicates that the connection is a WebSockets connection. ConnectionTypeWS ConnectionType = "websockets" )
func GetConnectionType ¶
func GetConnectionType(ctx context.Context) ConnectionType
GetConnectionType returns the connection type of the request if it was set by an RPCServer. A connection type of ConnectionTypeUnknown means that the connection type was not set.
type ErrClient ¶
type ErrClient struct {
// contains filtered or unexported fields
}
ErrClient is an error which occurred on the client side the library
type JSONRPCError ¶
type JSONRPCError struct { Code ErrorCode `json:"code"` Message string `json:"message"` Meta json.RawMessage `json:"meta,omitempty"` Data interface{} `json:"data,omitempty"` }
func (*JSONRPCError) Error ¶
func (e *JSONRPCError) Error() string
type RPCConnectionError ¶
type RPCConnectionError struct {
// contains filtered or unexported fields
}
func (*RPCConnectionError) Error ¶
func (e *RPCConnectionError) Error() string
func (*RPCConnectionError) Unwrap ¶
func (e *RPCConnectionError) Unwrap() error
type RPCErrorCodec ¶
type RPCErrorCodec interface { FromJSONRPCError(JSONRPCError) error ToJSONRPCError() (JSONRPCError, error) }
type RPCServer ¶
type RPCServer struct {
// contains filtered or unexported fields
}
RPCServer provides a jsonrpc 2.0 http server handler
func NewServer ¶
func NewServer(opts ...ServerOption) *RPCServer
NewServer creates new RPCServer instance
func (*RPCServer) AliasMethod ¶
func (*RPCServer) HandleRequest ¶
type RawParams ¶
type RawParams json.RawMessage
type ServerConfig ¶
type ServerConfig struct {
// contains filtered or unexported fields
}
type ServerOption ¶
type ServerOption func(c *ServerConfig)
func WithMaxRequestSize ¶
func WithMaxRequestSize(max int64) ServerOption
func WithParamDecoder ¶
func WithParamDecoder(t interface{}, decoder ParamDecoder) ServerOption
func WithReverseClient ¶
func WithReverseClient[RP any](namespace string) ServerOption
WithReverseClient will allow extracting reverse client on **WEBSOCKET** calls. RP is a proxy-struct type, much like the one passed to NewClient.
func WithServerErrors ¶
func WithServerErrors(es Errors) ServerOption
func WithServerPingInterval ¶
func WithServerPingInterval(d time.Duration) ServerOption
func WithTracer ¶
func WithTracer(l Tracer) ServerOption
WithTracer allows the instantiator to trace the method calls and results. This is useful for debugging a client-server interaction.