jsonrpc2: github.com/penguinn/jsonrpc2 Index | Files | Directories

package jsonrpc2

import "github.com/penguinn/jsonrpc2"

Package jsonrpc helps JSON-RPC 2.0 implements.

Index

Package Files

client.go debug.go doc.go error.go func.go handler.go jsonrpc.go method.go unmarshal.go

Constants

const (
    // Version is JSON-RPC 2.0.
    Version = "2.0"
)

Variables

var Filter func(context.Context, *Request) *Error

Filter runs before invoke a method.

func DebugHandler Uses

func DebugHandler(w http.ResponseWriter, r *http.Request)

DebugHandler views registered method list.

func Handler Uses

func Handler(w http.ResponseWriter, r *http.Request)

Handler provides basic JSON-RPC handling.

func Methods Uses

func Methods() map[string]Metadata

Methods returns registered methods.

func ParseRequest Uses

func ParseRequest(r *http.Request) ([]Request, bool, *Error)

ParseRequest parses a HTTP request to JSON-RPC request.

func PurgeMethods Uses

func PurgeMethods()

PurgeMethods purges all registered methods.

func RegisterMethod Uses

func RegisterMethod(method string, f Func, params, result interface{}) error

RegisterMethod registers jsonrpc.Func to MethodRepository.

func SendResponse Uses

func SendResponse(w http.ResponseWriter, resp []Response, batch bool) error

SendResponse writes JSON-RPC Resp.

type Client Uses

type Client struct {
    Url string
    // contains filtered or unexported fields
}

func NewClient Uses

func NewClient(url string) *Client

func (*Client) Call Uses

func (c *Client) Call(method string, params interface{}, id int) (*Resp, error)

func (*Client) CallTimeout Uses

func (c *Client) CallTimeout(method string, params interface{}, id int, timeout time.Duration) (*Resp, error)

type Error Uses

type Error struct {
    Code    ErrorCode   `json:"code"`
    Message string      `json:"message"`
    Data    interface{} `json:"data,omitempty"`
}

An Error is a wrapper for a JSON interface value.

func ErrInternal Uses

func ErrInternal() *Error

ErrInternal returns internal error.

func ErrInvalidParams Uses

func ErrInvalidParams() *Error

ErrInvalidParams returns invalid params error.

func ErrInvalidRequest Uses

func ErrInvalidRequest() *Error

ErrInvalidRequest returns invalid request error.

func ErrMethodNotFound Uses

func ErrMethodNotFound() *Error

ErrMethodNotFound returns method not found error.

func ErrParse Uses

func ErrParse() *Error

ErrParse returns parse error.

func Unmarshal Uses

func Unmarshal(params *json.RawMessage, dst interface{}) *Error

Unmarshal decodes JSON-RPC params.

func (*Error) Error Uses

func (e *Error) Error() string

Error implements error interface.

type ErrorCode Uses

type ErrorCode int

A ErrorCode by JSON-RPC 2.0.

const (
    // ErrorCodeParse is parse error code.
    ErrorCodeParse ErrorCode = -32700
    // ErrorCodeInvalidRequest is invalid request error code.
    ErrorCodeInvalidRequest ErrorCode = -32600
    // ErrorCodeMethodNotFound is method not found error code.
    ErrorCodeMethodNotFound ErrorCode = -32601
    // ErrorCodeInvalidParams is invalid params error code.
    ErrorCodeInvalidParams ErrorCode = -32602
    // ErrorCodeInternal is internal error code.
    ErrorCodeInternal ErrorCode = -32603
)

type Func Uses

type Func func(c context.Context, params *json.RawMessage) (result interface{}, err *Error)

Func links a method of JSON-RPC request.

func TakeMethod Uses

func TakeMethod(r Request) (Func, *Error)

TakeMethod takes jsonrpc.Func in MethodRepository.

type Metadata Uses

type Metadata struct {
    Func   Func
    Params interface{}
    Result interface{}
}

Metadata has method meta data.

type MethodReference Uses

type MethodReference struct {
    Name     string             `json:"name"`
    Function string             `json:"function"`
    Params   *jsonschema.Schema `json:"params,omitempty"`
    Result   *jsonschema.Schema `json:"result,omitempty"`
}

A MethodReference is a reference of JSON-RPC method.

type MethodRepository Uses

type MethodRepository struct {
    // contains filtered or unexported fields
}

A MethodRepository has JSON-RPC method functions.

type Request Uses

type Request struct {
    ID      *json.RawMessage `json:"id"`
    Version string           `json:"jsonrpc"`
    Method  string           `json:"method"`
    Params  *json.RawMessage `json:"params"`
}

A Request represents a JSON-RPC request received by the server.

type Resp Uses

type Resp struct {
    Id     int         `json:"id"`
    Result interface{} `json:"result"`
    Error  *RespError  `json:"error"`
}

type RespError Uses

type RespError struct {
    Code    int         `json:"code"`
    Message string      `json:"message"`
    Data    interface{} `json:"data"`
}

func (*RespError) Error Uses

func (this *RespError) Error() string

type Response Uses

type Response struct {
    ID      *json.RawMessage `json:"id,omitempty"`
    Version string           `json:"jsonrpc"`
    Result  interface{}      `json:"result,omitempty"`
    Error   *Error           `json:"error,omitempty"`
}

A Response represents a JSON-RPC Resp returned by the server.

func NewResponse Uses

func NewResponse(r Request) Response

NewResponse generates a JSON-RPC Resp.

Directories

PathSynopsis
example

Package jsonrpc2 imports 12 packages (graph) and is imported by 1 packages. Updated 2017-12-19. Refresh now. Tools for package owners.