Documentation ¶
Overview ¶
jsoff is JSONRPC 2.0 libaray in golang
Index ¶
- Constants
- Variables
- func DecodeInterface(input interface{}, output interface{}) error
- func DecodeParams(params []interface{}, outputPtr interface{}) error
- func EncodePretty(msg Message) (string, error)
- func ErrorResponse(w http.ResponseWriter, r *http.Request, err error, status int, message string)
- func GuessJson(input string) (interface{}, error)
- func GuessJsonArray(inputArr []string) ([]interface{}, error)
- func IsMethod(name string) bool
- func IsPublicMethod(name string) bool
- func MarshalJson(data interface{}) (string, error)
- func MessageBytes(msg Message) ([]byte, error)
- func MessageMap(msg Message) (map[string]interface{}, error)
- func MessageString(msg Message) string
- func MustMessageBytes(msg Message) []byte
- func NewUuid() string
- type BaseMessage
- func (self BaseMessage) IsError() bool
- func (self BaseMessage) IsNotify() bool
- func (self BaseMessage) IsRequest() bool
- func (self BaseMessage) IsResponse() bool
- func (self BaseMessage) IsResult() bool
- func (self BaseMessage) IsResultOrError() bool
- func (self *BaseMessage) SetTraceId(traceId string)
- func (self BaseMessage) TraceId() string
- type Bigint
- type ErrorMessage
- func NewErrorMessage(reqmsg Message, errbody *RPCError) *ErrorMessage
- func NewErrorMessageFromId(reqId interface{}, traceId string, errbody *RPCError) *ErrorMessage
- func RPCErrorMessage(reqmsg Message, code int, message string, data interface{}) *ErrorMessage
- func RPCErrorMessageFromId(reqId interface{}, traceId string, code int, message string, data interface{}) *ErrorMessage
- func (self ErrorMessage) HasResponseHeader() bool
- func (self *ErrorMessage) Interface() interface{}
- func (self ErrorMessage) Log() *log.Entry
- func (self ErrorMessage) MustError() *RPCError
- func (self ErrorMessage) MustId() interface{}
- func (self ErrorMessage) MustMethod() string
- func (self ErrorMessage) MustParams() []interface{}
- func (self ErrorMessage) MustResult() interface{}
- func (self ErrorMessage) ReplaceId(newId interface{}) Message
- func (self *ErrorMessage) ResponseHeader() http.Header
- type Message
- type NotifyMessage
- func (self *NotifyMessage) Interface() interface{}
- func (self NotifyMessage) Log() *log.Entry
- func (self NotifyMessage) MustError() *RPCError
- func (self NotifyMessage) MustId() interface{}
- func (self NotifyMessage) MustMethod() string
- func (self NotifyMessage) MustParams() []interface{}
- func (self NotifyMessage) MustResult() interface{}
- func (self NotifyMessage) ReplaceId(newId interface{}) Message
- type RPCError
- type RequestMessage
- func (self RequestMessage) CacheKey(prefix string) string
- func (self RequestMessage) Clone(newId interface{}) *RequestMessage
- func (self *RequestMessage) Interface() interface{}
- func (self RequestMessage) Log() *log.Entry
- func (self RequestMessage) MustError() *RPCError
- func (self RequestMessage) MustId() interface{}
- func (self RequestMessage) MustMethod() string
- func (self RequestMessage) MustParams() []interface{}
- func (self RequestMessage) MustResult() interface{}
- func (self RequestMessage) ReplaceId(newId interface{}) Message
- type ResponseMessage
- type ResultMessage
- func (self ResultMessage) HasResponseHeader() bool
- func (self *ResultMessage) Interface() interface{}
- func (self ResultMessage) Log() *log.Entry
- func (self ResultMessage) MustError() *RPCError
- func (self ResultMessage) MustId() interface{}
- func (self ResultMessage) MustMethod() string
- func (self ResultMessage) MustParams() []interface{}
- func (self ResultMessage) MustResult() interface{}
- func (self ResultMessage) ReplaceId(newId interface{}) Message
- func (self *ResultMessage) ResponseHeader() http.Header
- type UID
Constants ¶
const ( MKRequest = iota MKNotify MKResult MKError )
message kinds
Variables ¶
var ( ErrServerError = &RPCError{100, "server error", nil} ErrMethodNotFound = &RPCError{-32601, "method not found", nil} ErrEmptyMethod = &RPCError{-32601, "empty method", nil} ErrParseMessage = &RPCError{-32700, "parse error", nil} ErrInvalidRequest = &RPCError{-32600, "invalid request", nil} ErrInternalError = &RPCError{-32603, "internal error", nil} ErrMessageType = &RPCError{105, "wrong message type", nil} ErrTimeout = &RPCError{200, "request timeout", nil} ErrBadResource = &RPCError{201, "bad resource", nil} ErrLiveExit = &RPCError{202, "live exit", nil} ErrNotAllowed = &RPCError{406, "type not allowed", nil} ErrAuthFailed = &RPCError{401, "auth failed", nil} ErrInvalidSchema = &RPCError{-32633, "invalid schema", nil} )
error defination https://www.jsonrpc.org/specification#error_object
Functions ¶
func DecodeInterface ¶
func DecodeInterface(input interface{}, output interface{}) error
func DecodeParams ¶
func DecodeParams(params []interface{}, outputPtr interface{}) error
/ Convert params to a struct field by field
func ErrorResponse ¶
func GuessJsonArray ¶
func IsPublicMethod ¶
func MarshalJson ¶
func MessageBytes ¶
func MessageMap ¶
func MessageString ¶
func MustMessageBytes ¶ added in v0.5.8
Types ¶
type BaseMessage ¶
type BaseMessage struct {
// contains filtered or unexported fields
}
The base class of JSONRPC types
func (BaseMessage) IsError ¶
func (self BaseMessage) IsError() bool
IsError() returns if the message is a ErrorMessage
func (BaseMessage) IsNotify ¶
func (self BaseMessage) IsNotify() bool
IsNotify() returns if the message is a NotifyMessage
func (BaseMessage) IsRequest ¶
func (self BaseMessage) IsRequest() bool
IsRequest() returns if the message is a RequestMessage
func (BaseMessage) IsResponse ¶
func (self BaseMessage) IsResponse() bool
IsResponse() returns if the message is a RequestMessage or NotifyMessage
func (BaseMessage) IsResult ¶
func (self BaseMessage) IsResult() bool
IsResult() returns if the message is a ResultMessage
func (BaseMessage) IsResultOrError ¶
func (self BaseMessage) IsResultOrError() bool
IsResultOrError() returns if the message is a ResultMessage or ErrorMessage
func (*BaseMessage) SetTraceId ¶
func (self *BaseMessage) SetTraceId(traceId string)
func (BaseMessage) TraceId ¶
func (self BaseMessage) TraceId() string
type ErrorMessage ¶
type ErrorMessage struct { BaseMessage Id interface{} Error *RPCError // contains filtered or unexported fields }
Error message kind
func NewErrorMessage ¶
func NewErrorMessage(reqmsg Message, errbody *RPCError) *ErrorMessage
func NewErrorMessageFromId ¶
func NewErrorMessageFromId(reqId interface{}, traceId string, errbody *RPCError) *ErrorMessage
func RPCErrorMessage ¶
func RPCErrorMessage(reqmsg Message, code int, message string, data interface{}) *ErrorMessage
func RPCErrorMessageFromId ¶
func RPCErrorMessageFromId(reqId interface{}, traceId string, code int, message string, data interface{}) *ErrorMessage
func (ErrorMessage) HasResponseHeader ¶ added in v0.6.0
func (self ErrorMessage) HasResponseHeader() bool
func (*ErrorMessage) Interface ¶
func (self *ErrorMessage) Interface() interface{}
func (ErrorMessage) Log ¶
func (self ErrorMessage) Log() *log.Entry
func (ErrorMessage) MustError ¶
func (self ErrorMessage) MustError() *RPCError
func (ErrorMessage) MustId ¶
func (self ErrorMessage) MustId() interface{}
func (ErrorMessage) MustMethod ¶
func (self ErrorMessage) MustMethod() string
func (ErrorMessage) MustParams ¶
func (self ErrorMessage) MustParams() []interface{}
func (ErrorMessage) MustResult ¶
func (self ErrorMessage) MustResult() interface{}
func (ErrorMessage) ReplaceId ¶
func (self ErrorMessage) ReplaceId(newId interface{}) Message
func (*ErrorMessage) ResponseHeader ¶ added in v0.6.0
func (self *ErrorMessage) ResponseHeader() http.Header
type Message ¶
type Message interface { // Return's the judgement of message types IsRequest() bool IsNotify() bool IsResponse() bool IsResult() bool IsError() bool IsResultOrError() bool // TraceId can be used to analyse the flow of whole message // transportation SetTraceId(traceId string) TraceId() string // Returns template structures, this structure can be used to // marshal and turn into map Interface() interface{} // MustId returns the Id field of a message, will panic when // message is a Notify MustId() interface{} // MustMethod returns the method of a message, will panic when // message is an Result or Error. MustMethod() string // MustParams returns the params of a message, will panic when // message is a Result or Error MustParams() []interface{} // MustResult returns the result field of a message, will // panic when the message is not a Result MustResult() interface{} // MustError returns the error field of a message, will panic // when the message is not an Error MustError() *RPCError // Clone the message with a new Id ReplaceId(interface{}) Message // Log returns a Logger object with message specific // infomations attached. Log() *log.Entry }
The abstract interface of JSONRPC message. refer to https://www.jsonrpc.org/specification
data Message = Request id method params |
Notify method params | Result id result | Error id error={ code message data }
func ParseBytes ¶
type NotifyMessage ¶
type NotifyMessage struct { BaseMessage Method string Params []interface{} // contains filtered or unexported fields }
Notify message kind
func NewNotifyMessage ¶
func NewNotifyMessage(method string, params interface{}) *NotifyMessage
func (*NotifyMessage) Interface ¶
func (self *NotifyMessage) Interface() interface{}
func (NotifyMessage) Log ¶
func (self NotifyMessage) Log() *log.Entry
func (NotifyMessage) MustError ¶
func (self NotifyMessage) MustError() *RPCError
func (NotifyMessage) MustId ¶
func (self NotifyMessage) MustId() interface{}
func (NotifyMessage) MustMethod ¶
func (self NotifyMessage) MustMethod() string
func (NotifyMessage) MustParams ¶
func (self NotifyMessage) MustParams() []interface{}
func (NotifyMessage) MustResult ¶
func (self NotifyMessage) MustResult() interface{}
func (NotifyMessage) ReplaceId ¶
func (self NotifyMessage) ReplaceId(newId interface{}) Message
type RPCError ¶
type RPCError struct { Code int `json:"code"` Message string `json:"message"` Data interface{} `json:"data,omitempty"` }
RPC error object
func NewErrMsgType ¶
Create a new instance of ErrMessageType additional is the information to help identify error details
func ParamsError ¶
func (RPCError) ToMessage ¶
func (self RPCError) ToMessage(reqmsg *RequestMessage) *ErrorMessage
Convert RPCError to ErrorMessage, reqmsg is the original RequestMessage instance, the ErrorMessage will copy reqmsg's id property.
func (RPCError) ToMessageFromId ¶
func (self RPCError) ToMessageFromId(reqId interface{}, traceId string) *ErrorMessage
Convert RPCError to ErrorMessage, reqId and traceId can be used to compose the result error message
type RequestMessage ¶
type RequestMessage struct { BaseMessage Id interface{} Method string Params []interface{} // contains filtered or unexported fields }
Request message kind
func NewRequestMessage ¶
func NewRequestMessage(id interface{}, method string, params interface{}) *RequestMessage
func (RequestMessage) CacheKey ¶
func (self RequestMessage) CacheKey(prefix string) string
func (RequestMessage) Clone ¶
func (self RequestMessage) Clone(newId interface{}) *RequestMessage
func (RequestMessage) ReplaceId ¶
func (self RequestMessage) ReplaceId(newId interface{}) Message
type ResponseMessage ¶ added in v0.6.0
type ResultMessage ¶
type ResultMessage struct { BaseMessage Id interface{} Result interface{} // contains filtered or unexported fields }
Result message kind
func NewResultMessage ¶
func NewResultMessage(reqmsg Message, result interface{}) *ResultMessage
func (ResultMessage) HasResponseHeader ¶ added in v0.6.0
func (self ResultMessage) HasResponseHeader() bool
implements ResponseMessage
func (*ResultMessage) Interface ¶
func (self *ResultMessage) Interface() interface{}
func (ResultMessage) Log ¶
func (self ResultMessage) Log() *log.Entry
func (ResultMessage) MustError ¶
func (self ResultMessage) MustError() *RPCError
func (ResultMessage) MustId ¶
func (self ResultMessage) MustId() interface{}
func (ResultMessage) MustMethod ¶
func (self ResultMessage) MustMethod() string
func (ResultMessage) MustParams ¶
func (self ResultMessage) MustParams() []interface{}
func (ResultMessage) MustResult ¶
func (self ResultMessage) MustResult() interface{}
func (ResultMessage) ReplaceId ¶
func (self ResultMessage) ReplaceId(newId interface{}) Message
func (*ResultMessage) ResponseHeader ¶ added in v0.6.0
func (self *ResultMessage) ResponseHeader() http.Header
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cli
|
|
examples
|
|
interacting jsonrpc in http family specs, currently jsoffnet provides 3 mechanisms: the classical http/1.1, websocket and http/2 wire protocol.
|
interacting jsonrpc in http family specs, currently jsoffnet provides 3 mechanisms: the classical http/1.1, websocket and http/2 wire protocol. |