Documentation ¶
Index ¶
- Variables
- func PrepareDataHandler(ctx *fasthttp.RequestCtx)
- func ReadRequestParams(request *ServerRequest, args interface{}) error
- func WriteResponse(ctx *fasthttp.RequestCtx, status int, resp *ServerResponse)
- type APIServer
- type EmptyResponse
- type ServerRequest
- type ServerResponse
- type Service
- type ServiceMap
- type ServiceMethod
Constants ¶
This section is empty.
Variables ¶
var Version = "2.0"
Version is JSON RPC version that allowed to use
Functions ¶
func PrepareDataHandler ¶
func PrepareDataHandler(ctx *fasthttp.RequestCtx)
PrepareDataHandler process basic data to context values PrepareDataHandlerRequestErr.(error) and PrepareDataHandlerRequest.(*ServerRequest) and PrepareDataHandlerRequestRun.(int)
func ReadRequestParams ¶
func ReadRequestParams(request *ServerRequest, args interface{}) error
ReadRequestParams getting request parametrs
func WriteResponse ¶
func WriteResponse(ctx *fasthttp.RequestCtx, status int, resp *ServerResponse)
WriteResponse write response to client with status code and server response struct
Types ¶
type APIServer ¶
type APIServer struct {
// contains filtered or unexported fields
}
APIServer - main structure
func (*APIServer) APIHandler ¶
func (as *APIServer) APIHandler(ctx *fasthttp.RequestCtx)
APIHandler handle api request, process it and return result
func (*APIServer) GetAllServices ¶
GetAllServices returns an all registered services
The method name uses a dotted notation as in "Service.Method".
func (*APIServer) RegisterService ¶
RegisterService adds a new service to the server.
The name parameter is optional: if empty it will be inferred from the receiver type name.
Methods from the receiver will be extracted if these rules are satisfied:
- The receiver is exported (begins with an upper case letter) or local (defined in the package registering the service).
- The method name is exported.
- The method has three arguments: *http.Request, *args, *reply.
- All three arguments are pointers.
- The second and third arguments are exported or local.
- The method has return type error.
All other methods are ignored.
type ServerRequest ¶
type ServerRequest struct { // JSON-RPC protocol. Version string `json:"jsonrpc"` // A String containing the name of the method to be invoked. Method string `json:"method"` // A Structured value to pass as arguments to the method. Params *json.RawMessage `json:"params"` // The request id. MUST be a string, number or null. // Our implementation will not do type checking for id. // It will be copied as it is. ID *json.RawMessage `json:"id"` }
ServerRequest represents a JSON-RPC request received by the server.
type ServerResponse ¶
type ServerResponse struct { // JSON-RPC protocol. Version string `json:"jsonrpc"` // The Object that was returned by the invoked method. This must be null // in case there was an error invoking the method. // As per spec the member will be omitted if there was an error. Result interface{} `json:"result,omitempty"` // An Error object if there was an error invoking the method. It must be // null if there was no error. // As per spec the member will be omitted if there was no error. Error *jrpc2errors.Error `json:"error,omitempty"` // This must be the same id as the request it is responding to. ID *json.RawMessage `json:"id"` }
ServerResponse represents a JSON-RPC response returned by the server.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service - sub struct
type ServiceMap ¶
type ServiceMap struct {
// contains filtered or unexported fields
}
ServiceMap is a registry for services.
type ServiceMethod ¶
type ServiceMethod struct {
// contains filtered or unexported fields
}
ServiceMethod - sub struct