Documentation ¶
Index ¶
Constants ¶
const (
JsonRpcVersion = "2.0"
)
Variables ¶
This section is empty.
Functions ¶
func JrpcTypeString ¶
func JsonTypeString ¶
Types ¶
type BatchRequest ¶
type BatchRequest []Request
If the batch rpc call itself fails to be recognized as an valid JSON or as an Array with at least one value, the response from the Server MUST be a single Response object.
If there are no Response objects contained within the Response array as it is to be sent to the client, the server MUST NOT return an empty Array and should return nothing at all. I.E. Client send: "[]" => Server does not reply at all
func ParseBatchRequest ¶
func ParseBatchRequest(data []byte) *BatchRequest
Decodes byte slice to BatchRequest object and returns pointer to it. If the data was not compatible with an object this func will return nil
type BatchResponse ¶
type BatchResponse []Response
If the batch rpc call itself fails to be recognized as an valid JSON or as an Array with at least one value, the response from the Server MUST be a single Response object.
If there are no Response objects contained within the Response array as it is to be sent to the client, the server MUST NOT return an empty Array and should return nothing at all. I.E. Client send: "[]" => Server does not reply at all
func ParseBatchResponse ¶
func ParseBatchResponse(data []byte) *BatchResponse
Decodes byte slice to BatchResponse object and returns pointer to it. If the data was not compatible with an object this func will return nil
type Error ¶
type Error struct { // A Number that indicates the error type that occurred. // This MUST be an integer. Code ErrorCode `json:"code"` // A String providing a short description of the error. // The message SHOULD be limited to a concise single sentence. Message ErrorMsg `json:"message"` // A Primitive or Structured value that contains additional information about the error. // This may be omitted. // The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.). Data interface{} `json:"data,omitempty"` }
func NewError ¶
Returns new Error object with provided ErrorCode and data. Sets Error message using ErrorCode
func ParseError ¶
Decodes byte slice to Error object and returns pointer to it. If the data was not compatible with an object this func will return nil
type JrpcType ¶
type JrpcType int
JrpcType represents all JsonRpc specification types
func GetJrpcType ¶
Converts byte slice to JsonRpc and returns map[Object] and Type. [Request, Response, Notification, Error, BatchRequest, BatchResponse, None]
func Parse ¶
This function is more as an example and its own implementation is preferred.
// Example for own implementation: obj, tp := GetJrpcType(byteSlice) // would be wise to use switch{} on tp req := spec.Request{} mapstructure.Decode(obj, &req)
Decodes byte slice to one of JsonRpc types and returns data and JsonRpc type. for the working project.
// Example using Array: dataArray := []byte(`[{"jsonrpc":"2.0","method":"calc_add","params":[7,3],"id":4418}]`) ob, tp := spec.GetObject(dataArray) if tp == spec.TypeBatchRequest { request := ob.(spec.Request) fmt.Println(request) } // Example using Object: dataObject := []byte(`{"jsonrpc":"2.0","method":"calc_add","params":[7,3],"id":4418}`) ob, tp := spec.GetObject(dataArray) if tp == spec.TypeRequest { request := ob.(spec.Request) fmt.Println(request) }
type JsonType ¶
type JsonType int
JsonType represents json Array and Object
func GetJsonType ¶
Checks if is json type [Array, Object, None]
type Notification ¶
type Notification struct { // JSON-RPC protocol. MUST be exactly "2.0" Jsonrpc string `json:"jsonrpc"` // A String containing the name of the method to be invoked Method string `json:"method"` // A Structured value (array or object) that holds the parameter values to be // used during the invocation of the method. // // This member MAY be omitted. // // Array or Object from javascript JSON Params interface{} `json:"params"` }
func NewNotification ¶
func NewNotification() Notification
Returns new notification object with JsonRpc version attached
func ParseNotification ¶
func ParseNotification(data []byte) *Notification
Decodes byte slice to Notification object and returns pointer to it. If the data was not compatible with an object this func will return nil
type Request ¶
type Request struct { // JSON-RPC protocol. MUST be exactly "2.0" Jsonrpc string `json:"jsonrpc"` // A String containing the name of the method to be invoked Method string `json:"method"` // A Structured value that holds the parameter values to be // used during the invocation of the method. // // This member MAY be omitted. // // Array or Object from javascript JSON Params interface{} `json:"params"` // An identifier established by the Client that MUST contain // a String, Number, or NULL value // (this implementation ignores NULL) // // If it is not included it is assumed to be a notification. // // The Server MUST reply with the same value in the Response object if included. ID interface{} `json:"id,omitempty"` }
func ParseRequest ¶
Decodes byte slice to Request object and returns pointer to it. If the data was not compatible with an object this func will return nil
func (*Request) IsNotification ¶
Checks if request is a notification
type Response ¶
type Response struct { // JSON-RPC protocol. MUST be exactly "2.0" Jsonrpc string `json:"jsonrpc"` // This member is REQUIRED on success. // This member MUST NOT exist if there was an error invoking the method. // The value of this member is determined by the method invoked on the Server. Result interface{} `json:"result,omitempty"` // This member is REQUIRED on error. // This member MUST NOT exist if there was no error triggered during invocation. // The value for this member MUST be an Object as defined in section 5.1. Error *Error `json:"error,omitempty"` // This member is REQUIRED. // It MUST be the same as the value of the id member in the Request Object. // If there was an error in detecting the id in the Request object // (e.g. Parse error/Invalid Request), it MUST be Null. ID interface{} `json:"id"` }
func NewResponse ¶
func NewResponse(id interface{}, result interface{}) Response
Returns new Response object with provided ID and result object
func NewResponseError ¶
Returns new error Response object with provided ID and error object
func ParseResponse ¶
Decodes byte slice to Response object and returns pointer to it. If the data was not compatible with an object this func will return nil