Documentation ¶
Index ¶
- Variables
- func ContextWithClient(ctx context.Context, client *Client) context.Context
- func IsHTTPTransporterServerError(err error) bool
- type Client
- func (c *Client) GetFormatter() Formatter
- func (c *Client) GetIDGenerator() IDGenerator
- func (c *Client) GetPacker() Packer
- func (c *Client) GetPathGenerator() PathGenerator
- func (c *Client) GetService() string
- func (c *Client) GetTransporter() Transporter
- func (c *Client) Invoke(ctx context.Context, method string, request any, response any, ...) (err error)
- func (c *Client) Use(m ...Middleware)
- type Formatter
- type FormatterKind
- type FullPathGenerator
- type GeneralPathGenerator
- type HTTPTransporter
- type HTTPTransporterOption
- type HTTPTransporterServerError
- type Handler
- type IDGenerator
- type IDGeneratorFunc
- type JSONPacker
- type JSONRPCFormatter
- func (j *JSONRPCFormatter) FormatRequest(req *RPCRequest) ([]byte, error)
- func (j *JSONRPCFormatter) FormatResponse(resp *RPCResponse, err *RPCResponseError) ([]byte, error)
- func (j *JSONRPCFormatter) Kind() FormatterKind
- func (j *JSONRPCFormatter) ParseRequest(data []byte) (*RPCRequest, error)
- func (j *JSONRPCFormatter) ParseResponse(data []byte) (*RPCResponse, error)
- type JSONRPCFormatterRequest
- type JSONRPCFormatterResponse
- type JSONRPCFormatterResponseError
- type Middleware
- type Option
- func WithFormatter(formatter Formatter) Option
- func WithIDGenerator(generator IDGenerator) Option
- func WithMiddleware(m ...Middleware) Option
- func WithPacker(packer Packer) Option
- func WithPathGenerator(generator PathGenerator) Option
- func WithService(service string) Option
- func WithTransporter(transporter Transporter) Option
- type Packer
- type PathGenerator
- type PathGeneratorFunc
- type RPCRequest
- type RPCResponse
- type RPCResponseError
- type Transporter
- type UUIDGenerator
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrClientServiceIsRequired = errors.New("jet/client: service is required") ErrClientTransporterIsRequired = errors.New("jet/client: transporter is required") )
View Source
var ( ErrHTTPTransporterAddrIsRequired = errors.New("jet/transporter: Addr is required") ErrorHTTPTransporterClientIsRequired = errors.New("jet/transporter: client is required") )
View Source
var JSONRPCVersion = "2.0"
JSONRPCVersion is the json rpc version
Functions ¶
func ContextWithClient ¶ added in v2.24.0
ContextWithClient returns a new Context that carries value.
func IsHTTPTransporterServerError ¶ added in v2.18.1
IsHTTPTransporterServerError reports whether err was created by HTTPTransporterServerError.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func ClientFromContext ¶ added in v2.24.0
ClientFromContext returns the Client value stored in ctx, if any.
func (*Client) GetFormatter ¶ added in v2.18.1
func (*Client) GetIDGenerator ¶ added in v2.18.1
func (c *Client) GetIDGenerator() IDGenerator
func (*Client) GetPathGenerator ¶ added in v2.18.1
func (c *Client) GetPathGenerator() PathGenerator
func (*Client) GetService ¶ added in v2.18.1
func (*Client) GetTransporter ¶ added in v2.18.1
func (c *Client) GetTransporter() Transporter
func (*Client) Use ¶
func (c *Client) Use(m ...Middleware)
type Formatter ¶
type Formatter interface { Kind() FormatterKind // FormatRequest formats a request FormatRequest(req *RPCRequest) ([]byte, error) // FormatResponse formats a response FormatResponse(resp *RPCResponse, err *RPCResponseError) ([]byte, error) // ParseRequest parses a request ParseRequest(data []byte) (*RPCRequest, error) // ParseResponse parses a response ParseResponse(data []byte) (*RPCResponse, error) }
var DefaultFormatter Formatter = NewJSONRPCFormatter()
type FormatterKind ¶ added in v2.24.0
type FormatterKind string
const (
FormatterKindJSONRPC FormatterKind = "jsonrpc"
)
type FullPathGenerator ¶
type FullPathGenerator struct{}
FullPathGenerator generates the full path of the service method
func NewFullPathGenerator ¶
func NewFullPathGenerator() *FullPathGenerator
type GeneralPathGenerator ¶
type GeneralPathGenerator struct{}
GeneralPathGenerator generates the general path of the service method
func NewGeneralPathGenerator ¶
func NewGeneralPathGenerator() *GeneralPathGenerator
type HTTPTransporter ¶
HTTPTransporter is a http transporter
func NewHTTPTransporter ¶
func NewHTTPTransporter(opts ...HTTPTransporterOption) (*HTTPTransporter, error)
type HTTPTransporterOption ¶
type HTTPTransporterOption func(*HTTPTransporter)
func WithHTTPTransporterAddr ¶
func WithHTTPTransporterAddr(addr string) HTTPTransporterOption
func WithHTTPTransporterClient ¶
func WithHTTPTransporterClient(client *http.Client) HTTPTransporterOption
type HTTPTransporterServerError ¶ added in v2.18.1
func (*HTTPTransporterServerError) Error ¶ added in v2.18.1
func (e *HTTPTransporterServerError) Error() string
func (*HTTPTransporterServerError) Unwrap ¶ added in v2.18.1
func (e *HTTPTransporterServerError) Unwrap() error
type IDGenerator ¶
type IDGenerator interface {
Generate() string
}
var DefaultIDGenerator IDGenerator = NewUUIDGenerator()
type IDGeneratorFunc ¶
type IDGeneratorFunc func() string
func (IDGeneratorFunc) Generate ¶
func (f IDGeneratorFunc) Generate() string
type JSONPacker ¶
type JSONPacker struct{}
JSONPacker is a json packer
func NewJSONPacker ¶
func NewJSONPacker() *JSONPacker
type JSONRPCFormatter ¶
type JSONRPCFormatter struct{}
JSONRPCFormatter is a json rpc formatter
func NewJSONRPCFormatter ¶
func NewJSONRPCFormatter() *JSONRPCFormatter
func (*JSONRPCFormatter) FormatRequest ¶
func (j *JSONRPCFormatter) FormatRequest(req *RPCRequest) ([]byte, error)
func (*JSONRPCFormatter) FormatResponse ¶
func (j *JSONRPCFormatter) FormatResponse(resp *RPCResponse, err *RPCResponseError) ([]byte, error)
func (*JSONRPCFormatter) Kind ¶ added in v2.24.0
func (j *JSONRPCFormatter) Kind() FormatterKind
func (*JSONRPCFormatter) ParseRequest ¶
func (j *JSONRPCFormatter) ParseRequest(data []byte) (*RPCRequest, error)
func (*JSONRPCFormatter) ParseResponse ¶
func (j *JSONRPCFormatter) ParseResponse(data []byte) (*RPCResponse, error)
type JSONRPCFormatterRequest ¶
type JSONRPCFormatterRequest struct { Jsonrpc string `json:"jsonrpc"` Method string `json:"method"` Params json.RawMessage `json:"params"` ID string `json:"id"` }
type JSONRPCFormatterResponse ¶
type JSONRPCFormatterResponse struct { Jsonrpc string `json:"jsonrpc"` Result json.RawMessage `json:"result"` ID string `json:"id"` Error *JSONRPCFormatterResponseError `json:"error"` }
type Middleware ¶
func Chain ¶
func Chain(m ...Middleware) Middleware
Chain chains the middlewares.
Chain(m1, m2, m3)(xxx) => m1(m2(m3(xxx))
type Option ¶
type Option func(*Client)
func WithFormatter ¶
func WithIDGenerator ¶
func WithIDGenerator(generator IDGenerator) Option
func WithMiddleware ¶
func WithMiddleware(m ...Middleware) Option
func WithPacker ¶
func WithPathGenerator ¶
func WithPathGenerator(generator PathGenerator) Option
func WithService ¶
func WithTransporter ¶
func WithTransporter(transporter Transporter) Option
type Packer ¶
var DefaultPacker Packer = NewJSONPacker()
type PathGenerator ¶
var DefaultPathGenerator PathGenerator = NewGeneralPathGenerator()
type PathGeneratorFunc ¶
PathGeneratorFunc generates the path of the service method
type RPCRequest ¶
type RPCResponse ¶
type RPCResponseError ¶
type RPCResponseError struct { ID string `json:"id"` Code int `json:"code"` Message string `json:"message"` Err error `json:"error"` }
func (*RPCResponseError) Error ¶
func (r *RPCResponseError) Error() string
type Transporter ¶
type UUIDGenerator ¶
type UUIDGenerator struct{}
func NewUUIDGenerator ¶
func NewUUIDGenerator() *UUIDGenerator
func (*UUIDGenerator) Generate ¶
func (u *UUIDGenerator) Generate() string
Source Files ¶
Click to show internal directories.
Click to hide internal directories.