jrpc2server: github.com/riftbit/jrpc2server Index | Files

package jrpc2server

import "github.com/riftbit/jrpc2server"


Package Files

helpers.go json_codec.go service.go


var Version = "2.0"

Version is JSON RPC version that allowed to use

func PrepareDataHandler Uses

func PrepareDataHandler(ctx *fasthttp.RequestCtx)

PrepareDataHandler process basic data to context values PrepareDataHandlerRequestErr.(error) and PrepareDataHandlerRequest.(*ServerRequest) and PrepareDataHandlerRequestRun.(int)

func ReadRequestParams Uses

func ReadRequestParams(request *ServerRequest, args interface{}) error

ReadRequestParams getting request parametrs

func WriteResponse Uses

func WriteResponse(ctx *fasthttp.RequestCtx, status int, resp *ServerResponse)

WriteResponse write response to client with status code and server response struct

type APIServer Uses

type APIServer struct {
    // contains filtered or unexported fields

APIServer - main structure

func NewServer Uses

func NewServer() *APIServer

NewServer returns a new RPC server.

func (*APIServer) APIHandler Uses

func (as *APIServer) APIHandler(ctx *fasthttp.RequestCtx)

APIHandler handle api request, process it and return result

func (*APIServer) GetAllServices Uses

func (as *APIServer) GetAllServices() (map[string]*Service, error)

GetAllServices returns an all registered services

The method name uses a dotted notation as in "Service.Method".

func (*APIServer) RegisterService Uses

func (as *APIServer) RegisterService(receiver interface{}, name string) error

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 EmptyResponse Uses

type EmptyResponse struct{}

EmptyResponse empty response

type ServerRequest Uses

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 Uses

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 Uses

type Service struct {
    // contains filtered or unexported fields

Service - sub struct

type ServiceMap Uses

type ServiceMap struct {
    // contains filtered or unexported fields

ServiceMap is a registry for services.

type ServiceMethod Uses

type ServiceMethod struct {
    // contains filtered or unexported fields

ServiceMethod - sub struct

Package jrpc2server imports 11 packages (graph). Updated 2018-12-05. Refresh now. Tools for package owners.