jsonrpc: github.com/lillilli/jsonrpc Index | Files | Directories

package jsonrpc

import "github.com/lillilli/jsonrpc"

Index

Package Files

error.go handler.go jsonrpc.go request.go response.go server.go

Constants

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

type Handler Uses

type Handler func(w ResponseWriter, r *Request) error

Handler represents jsonrpc handler.

if your handler return any error, and you don`t use SetInvalidRequestParamsError() response will have code -32603 and message "Internal error"

if you use SetInvalidRequestParamsError() response will have code -32602 and message "Invalid params"

type Request Uses

type Request struct {
    Version string          `json:"jsonrpc"`
    Method  string          `json:"method"`
    Params  json.RawMessage `json:"params"`
    ID      interface{}     `json:"id"`
    // contains filtered or unexported fields
}

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

func (*Request) Unmarshal Uses

func (r *Request) Unmarshal(v interface{}) error

Unmarshal unmarshal req params to specified structure. Unmarshal will set parse error if unmarshaling failed.

type ResponseWriter Uses

type ResponseWriter interface {
    // SetResponse set response result.
    SetResponse(v interface{})

    // SetErrorData set response error data.
    // Error will have -32603 status code and message equal to "Internal error".
    SetErrorData(v interface{})

    // SetInvalidRequestParamsError set response error to invalid req params.
    // Error will have -32602 status code and message equal to "Invalid params".
    SetInvalidRequestParamsError(data interface{})
}

ResponseWriter represents JSON-RPC response writer interface.

type Server Uses

type Server interface {
    // Handle set up method handler.
    Handle(method string, handler Handler)

    // Handler return standart net/http handler.
    Handler() http.Handler
}

Server represents jsonrpc server interface.

func NewServer Uses

func NewServer() Server

NewServer returns new jsonrpc server instance.

Directories

PathSynopsis
example

Package jsonrpc imports 6 packages (graph) and is imported by 1 packages. Updated 2019-02-27. Refresh now. Tools for package owners.