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
- type Closer
- type Config
- type ErrClient
- type ErrorCode
- type Errors
- type Option
- type ParamDecoder
- type ParamEncoder
- type RPCConnectionError
- type RPCServer
- type RawParams
- type ServerConfig
- type ServerOption
- type State
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 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 Closer ¶
type Closer interface {
// Close method is called when the state ends, and can be used by clients to clean up lingering state if needed
Close()
}
type ErrClient ¶
type ErrClient struct {
// contains filtered or unexported fields
}
ErrClient is an error which occurred on the client side the library
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 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 ¶
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