Documentation
¶
Overview ¶
Package jsonrpc implements use case transport for JSON-RPC 2.0 on top of HTTP.
Index ¶
- Constants
- func SwguiSettings(settingsUI map[string]string, rpcPath string) map[string]string
- type ErrWithAppCode
- type ErrWithCanonicalStatus
- type ErrWithFields
- type Error
- type ErrorCode
- type Handler
- type JSONSchemaValidator
- func (jv *JSONSchemaValidator) AddParamsSchema(method string, jsonSchema []byte) error
- func (jv *JSONSchemaValidator) AddResultSchema(method string, jsonSchema []byte) error
- func (jv *JSONSchemaValidator) ValidateParams(method string, jsonBody []byte) error
- func (jv *JSONSchemaValidator) ValidateResult(method string, jsonBody []byte) error
- type OpenAPI
- type Request
- type Response
- type ValidationErrors
- type Validator
Constants ¶
const ( CodeParseError = ErrorCode(-32700) CodeInvalidRequest = ErrorCode(-32600) CodeMethodNotFound = ErrorCode(-32601) CodeInvalidParams = ErrorCode(-32602) CodeInternalError = ErrorCode(-32603) )
Standard error codes.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ErrWithAppCode ¶
ErrWithAppCode exposes application error code.
type ErrWithCanonicalStatus ¶
ErrWithCanonicalStatus exposes canonical status code.
type ErrWithFields ¶
ErrWithFields exposes structured context of error.
type Error ¶
type Error struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
Error describes JSON-RPC error structure.
type Handler ¶
type Handler struct {
OpenAPI *OpenAPI
Validator Validator
Middlewares []usecase.Middleware
SkipParamsValidation bool
SkipResultValidation bool
// contains filtered or unexported fields
}
Handler serves JSON-RPC 2.0 methods with HTTP.
func (*Handler) Add ¶
func (h *Handler) Add(u usecase.Interactor)
Add registers use case interactor as JSON-RPC method.
type JSONSchemaValidator ¶
type JSONSchemaValidator struct {
// contains filtered or unexported fields
}
JSONSchemaValidator implements Validator with JSON Schema.
func (*JSONSchemaValidator) AddParamsSchema ¶
func (jv *JSONSchemaValidator) AddParamsSchema(method string, jsonSchema []byte) error
AddParamsSchema registers parameters schema.
func (*JSONSchemaValidator) AddResultSchema ¶
func (jv *JSONSchemaValidator) AddResultSchema(method string, jsonSchema []byte) error
AddResultSchema registers result schema.
func (*JSONSchemaValidator) ValidateParams ¶
func (jv *JSONSchemaValidator) ValidateParams(method string, jsonBody []byte) error
ValidateParams validates parameters value with JSON schema.
func (*JSONSchemaValidator) ValidateResult ¶
func (jv *JSONSchemaValidator) ValidateResult(method string, jsonBody []byte) error
ValidateResult validates result value with JSON schema.
type OpenAPI ¶
type OpenAPI struct {
BasePath string // URL path to docs, default "/docs/".
// contains filtered or unexported fields
}
OpenAPI extracts OpenAPI documentation from HTTP handler and underlying use case interactor.
func (*OpenAPI) Annotate ¶
Annotate adds OpenAPI operation configuration that is applied during collection.
func (*OpenAPI) Collect ¶
func (c *OpenAPI) Collect( name string, u usecase.Interactor, v Validator, annotations ...func(*openapi3.Operation) error, ) (err error)
Collect adds use case handler to documentation.
type Request ¶
type Request struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params json.RawMessage `json:"params"`
ID *interface{} `json:"id,omitempty"`
}
Request is an JSON-RPC request item.
type Response ¶
type Response struct {
JSONRPC string `json:"jsonrpc"`
Result json.RawMessage `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
ID *interface{} `json:"id"`
}
Response is an JSON-RPC response item.
type ValidationErrors ¶
ValidationErrors is a list of validation errors.
Key is field position (e.g. "path:id" or "body"), value is a list of issues with the field.
func (ValidationErrors) Error ¶
func (re ValidationErrors) Error() string
Error returns error message.
func (ValidationErrors) Fields ¶
func (re ValidationErrors) Fields() map[string]interface{}
Fields returns request errors by field location and name.
type Validator ¶
type Validator interface {
ValidateParams(method string, jsonBody []byte) error
ValidateResult(method string, jsonBody []byte) error
AddParamsSchema(method string, jsonSchema []byte) error
AddResultSchema(method string, jsonSchema []byte) error
}
Validator defines a contract of JSON Schema validator.
