Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HTTPHandleFunc ¶
func HTTPHandleFunc(m *Manager) func(w http.ResponseWriter, r *http.Request)
HTTPHandleFunc it's an helper function to mediate http requests to JSON RPC and back.
Types ¶
type Error ¶
type Error struct { Code ErrorCode `json:"code"` Message string `json:"message"` Data interface{} `json:"data,omitempty"` }
Error represents a JSON-RPC error, the Response MUST contain the error member if the RPC call encounters an error.
Code - A Number that indicates the error type that occurred. This MUST be an integer.
Message - A String providing a short description of the error. SHOULD be limited to a concise single sentence.
Data - A Primitive or Structured value that contains additional information about the error.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager represent the JSON RPC method register manager.
type ManagerBuilder ¶
type ManagerBuilder struct {
// contains filtered or unexported fields
}
ManagerBuilder will support the Builder pattern for the Manager struct.
func NewManagerBuilder ¶
func NewManagerBuilder() *ManagerBuilder
NewManagerBuilder will return a new builder for the Manager.
func (*ManagerBuilder) Add ¶
func (mb *ManagerBuilder) Add(name string, h Method) *ManagerBuilder
Add will append a new method to the manager to be executed. the name should be unique if the name name is used more then one time it will overwrite the handler of that method.
If the name is empty or the h is nil this function will panic.
func (*ManagerBuilder) Build ¶
func (mb *ManagerBuilder) Build() Manager
Build will use the configuration collected during the build return a manager with these configurations.
func (*ManagerBuilder) SetTimeout ¶
func (mb *ManagerBuilder) SetTimeout(timeout time.Duration) *ManagerBuilder
SetTimeout allows to specify a custom timeout for each method execution.
Default timeout is 10 seconds
type Method ¶
A Method responds to an JSON RPC request.
Execute should write reply result to the Response and then return. Returning signals that the request is finished
type Request ¶
type Request struct { Version string `json:"jsonrpc"` Method string `json:"method"` ID *json.RawMessage `json:"id,omitempty"` Params *json.RawMessage `json:"params,omitempty"` // contains filtered or unexported fields }
Request represents a JSON-RPC call to the server and contains the following.
Version - A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".
Method - A String containing the name of the method to be invoked.
ID - An identifier established by the Client that MUST contain a String, Number, or NULL value if included. If it is not included it is assumed to be a notification. The value SHOULD normally not be Null and Numbers SHOULD NOT contain fractional parts.
Params - A Structured value that holds the parameter values to be used during the invocation of the method.
func (*Request) Context ¶
Context returns the request's context. To change the context, use WithContext.
The returned context is always non-nil; it defaults to the background context.
func (*Request) ParseParams ¶
ParseParams will get the params from the request and and stores the result in the value pointed to by v.
Request.Params is optional but if we are calling the function they need to be there otherwise returns ErrInvalidParams.
type Response ¶
type Response struct { Version string `json:"jsonrpc"` ID *json.RawMessage `json:"id"` Result interface{} `json:"result,omitempty"` Error *Error `json:"error,omitempty"` }
Response represents a JSON-RPC response from the server and containers the following.
Version - A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".
Result -
Error -