jsonrpc

package module
v0.0.0-...-3e6a48a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2018 License: MIT Imports: 9 Imported by: 0

README

jsonrpc

Install:

go get -u github.com/FSX/jsonrpc

It's not completely done yet. There are TODOs in the code that tell what has to be done.

Documentation

Index

Constants

View Source
const (
	CodeParseError     = -32700
	CodeInvalidRequest = -32600
	CodeMethodNotFound = -32601
	CodeInvalidParams  = -32602
	CodeInternalError  = -32603
)

JSONRPC 2.0 error codes.

View Source
const ProtocolVersion = "2.0"

Variables

This section is empty.

Functions

func NewMethod

func NewMethod(name string, function interface{}) (*method, error)

func Reply

func Reply(w io.Writer, id Id, result interface{}) error

func ReplyWithError

func ReplyWithError(w io.Writer, id Id, code int64, message string) error

func ReplyWithErrorData

func ReplyWithErrorData(w io.Writer, id Id, code int64, message string, data interface{}) error

func ReplyWithErrorObject

func ReplyWithErrorObject(w io.Writer, id Id, obj *Error) error

Types

type BatchRequest

type BatchRequest []*Request

func (BatchRequest) MarshalEasyJSON

func (v BatchRequest) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (BatchRequest) MarshalJSON

func (v BatchRequest) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*BatchRequest) UnmarshalEasyJSON

func (v *BatchRequest) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*BatchRequest) UnmarshalJSON

func (v *BatchRequest) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type BatchResponse

type BatchResponse []*Response

func (BatchResponse) MarshalEasyJSON

func (v BatchResponse) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (BatchResponse) MarshalJSON

func (v BatchResponse) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*BatchResponse) UnmarshalEasyJSON

func (v *BatchResponse) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*BatchResponse) UnmarshalJSON

func (v *BatchResponse) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Error

type Error struct {
	Code    int64            `json:"code"`
	Message string           `json:"message"`
	Data    *json.RawMessage `json:"data,omitempty"`
}

Error represents a JSON-RPC response error.

func ErrorWithData

func ErrorWithData(code int64, message string, data interface{}) (*Error, error)

func (*Error) Error

func (e *Error) Error() string

func (Error) MarshalEasyJSON

func (v Error) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Error) MarshalJSON

func (v Error) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Error) UnmarshalEasyJSON

func (v *Error) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Error) UnmarshalJSON

func (v *Error) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Id

type Id string

Id represents a JSON-RPC 2.0 request ID. TODO: Support integers and null.

type Message

type Message struct {
	Request       *Request
	Response      *Response
	BatchRequest  BatchRequest
	BatchResponse BatchResponse
}

Message holds one of the unmarshaled messages (request or response).

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(data []byte) error

type Request

type Request struct {
	JSONRPC string           `json:"jsonrpc"`
	Method  string           `json:"method"`
	Params  *json.RawMessage `json:"params,omitempty"`
	Id      Id               `json:"id,omitempty"`
}

Request represents a JSON-RPC request or notification.

func (*Request) IsNotification

func (r *Request) IsNotification() bool

func (Request) MarshalEasyJSON

func (v Request) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Request) MarshalJSON

func (v Request) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Request) UnmarshalEasyJSON

func (v *Request) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Request) UnmarshalJSON

func (v *Request) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Response

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

Response represents a JSON-RPC response.

func (Response) MarshalEasyJSON

func (v Response) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Response) MarshalJSON

func (v Response) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Response) UnmarshalEasyJSON

func (v *Response) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Response) UnmarshalJSON

func (v *Response) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Router

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

func NewRouter

func NewRouter(functions map[string]interface{}) (*Router, error)

func (*Router) Handle

func (r *Router) Handle(w io.Writer, req *Request)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL