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 ¶ added in v0.2.0
todo is there a better way to tell 'struct with any number of fields'?
func ExtractReverseClient ¶ added in v0.2.0
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 ¶ added in v0.2.0
func WithClientHandlerAlias ¶ added in v0.2.0
WithClientHandlerAlias creates an alias for a client HANDLER method - for handlers created with WithClientHandler
func WithErrors ¶ added in v0.1.6
func WithHTTPClient ¶ added in v0.2.0
func WithNoReconnect ¶ added in v0.1.2
func WithNoReconnect() func(c *Config)
func WithParamEncoder ¶ added in v0.1.1
func WithParamEncoder(t interface{}, encoder ParamEncoder) func(c *Config)
func WithPingInterval ¶ added in v0.1.2
Must be < Timeout/2
func WithReconnectBackoff ¶ added in v0.1.1
func WithTimeout ¶ added in v0.1.2
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 ¶ added in v0.5.0
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 ¶ added in v0.6.0
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 ¶ added in v0.6.0
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 ¶ added in v0.7.0
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 ¶ added in v0.7.0
func (e *JSONRPCError) Error() string
type ParamDecoder ¶ added in v0.1.1
type RPCConnectionError ¶ added in v0.1.7
type RPCConnectionError struct {
// contains filtered or unexported fields
}
func (*RPCConnectionError) Error ¶ added in v0.1.7
func (e *RPCConnectionError) Error() string
func (*RPCConnectionError) Unwrap ¶ added in v0.1.7
func (e *RPCConnectionError) Unwrap() error
type RPCErrorCodec ¶ added in v0.7.0
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 ¶ added in v0.1.2
func (*RPCServer) HandleRequest ¶ added in v0.5.0
type RawParams ¶ added in v0.2.0
type RawParams json.RawMessage
type ServerConfig ¶ added in v0.1.1
type ServerConfig struct {
// contains filtered or unexported fields
}
type ServerOption ¶ added in v0.1.1
type ServerOption func(c *ServerConfig)
func WithMaxRequestSize ¶ added in v0.1.2
func WithMaxRequestSize(max int64) ServerOption
func WithParamDecoder ¶ added in v0.1.1
func WithParamDecoder(t interface{}, decoder ParamDecoder) ServerOption
func WithReverseClient ¶ added in v0.2.0
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 ¶ added in v0.1.6
func WithServerErrors(es Errors) ServerOption
func WithServerPingInterval ¶ added in v0.2.0
func WithServerPingInterval(d time.Duration) ServerOption
func WithTracer ¶ added in v0.6.0
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.