Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API interface {
APIs() APISet
}
API defines an interface for providing and accessing API functions. Packages that offer services accessed via RPC or any service-oriented interface must implement it.
type APISet ¶
type APISet []MethodInfo
APISet defines a collection of APIs
func (*APISet) Add ¶
func (a *APISet) Add(api MethodInfo)
Get gets an API function by name and namespace
func (*APISet) Get ¶
func (a *APISet) Get(name string) *MethodInfo
Get gets an API function by name and namespace
type CallContext ¶
type CallContext struct { // IsLocal indicates that the request originated locally IsLocal bool }
CallContext contains information about an RPC request
type Err ¶
type Err struct { Code string `json:"code"` Message string `json:"message"` Data interface{} `json:"data,omitempty"` }
Err represents JSON RPC error object
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is responsible for handling incoming RPC requests by routing to a method that can handle the request and return a response.
func (*Handler) HasAPI ¶
func (s *Handler) HasAPI(api MethodInfo) bool
HasAPI checks whether an API with matching full name exist
func (*Handler) MergeAPISet ¶
MergeAPISet merges an API set with s current api sets
func (*Handler) Methods ¶
func (s *Handler) Methods() (methodsInfo []MethodInfo)
Methods gets the names of all methods in the API set.
type MethodInfo ¶
type MethodInfo struct { // Func is the API function to be executed. // Must be Method or MethodWithContext Func interface{} `json:"-"` // Namespace is the namespace where the method is under Namespace string `json:"namespace"` // Name is the name of the method Name string `json:"name"` // Private indicates a requirement for a private, authenticated // user session before this API function is executed. Private bool `json:"private"` // Desc describes the API Desc string `json:"description"` }
MethodInfo describes an RPC method.
func (*MethodInfo) FullName ¶
func (a *MethodInfo) FullName() string
type MethodWithContext ¶
type MethodWithContext func(params interface{}, ctx *CallContext) *Response
type OnRequestFunc ¶
OnRequestFunc is the type of function to use as a callback when newRPCHandler requests are received
type Request ¶
type Request struct { JSONRPCVersion string `json:"jsonrpc"` Method string `json:"method"` Params interface{} `json:"params"` ID interface{} `json:"id,omitempty"` }
Request represent a JSON RPC request
func (Request) IsNotification ¶
IsNotification checks whether the request is a notification according to JSON RPC specification. When ID is nil, we assume it's a notification request.
type Response ¶
type Response struct { JSONRPCVersion string `json:"jsonrpc"` Result util.Map `json:"result"` Err *Err `json:"error,omitempty"` ID interface{} `json:"id,omitempty"` // string or float64 }
Response represents a JSON RPC response
func StatusOK ¶
func StatusOK() *Response
StatusOK creates a success response with data `{status:true}`