jsonrpc

package
v0.3.2-e935 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JSON-RPC protocol version.
	Version = "2.0"
	// JSON-RPC protocol error codes.
	ParseError     = -32700
	InvalidRequest = -32600
	MethodNotFound = -32601
	InvalidParams  = -32602
	InternalError  = -32603
)

Variables

This section is empty.

Functions

func Call

func Call(url string, reqData Request, rpcUser string, rpcPassword string) (interface{}, error)

Call is a util method to send a JSON-RPC request to server.

func CallArray

func CallArray(url, method string, params ...interface{}) (interface{}, error)

CallArray is a util method to send a JSON-RPC request to server.

func CallParams

func CallParams(url, method string, params htp.Params) (interface{}, error)

Types

type Config

type Config struct {
	Path      string
	ServePort uint16
	User      string
	Pass      string
	WhiteList []string
	NetListen func(port uint16) (net.Listener, error)
}

Config is the configuration of the JSON-RPC server.

type Handler

type Handler func(htp.Params) (interface{}, error)

Handler is the registered method to handle a http request.

type Request

type Request struct {
	Id      interface{} `json:"id"`
	Version string      `json:"jsonrpc"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params"`
}

Request represent the standard JSON-RPC request data structure.

type Response

type Response struct {
	Id      interface{} `json:"id"`
	Version string      `json:"jsonrpc"`
	Result  interface{} `json:"result"`
	Error   *htp.Error  `json:"error"`
}

Response represent the standard JSON-RPC Response data structure.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the JSON-RPC server instance class.

func NewServer

func NewServer(cfg *Config) *Server

NewServer creates and return a JSON-RPC server instance.

func (*Server) RegisterAction

func (s *Server) RegisterAction(name string, handler Handler, params ...string)

RegisterAction register a service handler method by it's name and parameters. When a JSON-RPC client's request method matches the registered handler name, it will be invoked. This method is safe for concurrency access.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) Start

func (s *Server) Start() error

func (*Server) Stop

func (s *Server) Stop() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL