rpc

package
v0.18.15 Latest Latest
Warning

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

Go to latest
Published: May 17, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Pre-defined errors for JSON-RPC 2.0 https://www.jsonrpc.org/specification#error_object
	CodeParseError     = -32700
	CodeInvalidRequest = -32600
	CodeMethodNotFound = -32601
	CodeInvalidParams  = -32602
	CodeInternalError  = -32603

	// -32000 to -32099 Are application level errors (i.e. define your rpc errors in this range)
	CodeNotAllowed = -32001

	CodeNotFound = -32000
)
View Source
const (
	// All incoming requests must show this MIME type in the header
	ContentType = "application/json"

	PathJSON = "/jsonrpc"
	PathGOB  = "/rpc/gob"
	Path     = PathJSON
)

The http path used for our rpc handlers

Variables

This section is empty.

Functions

This section is empty.

Types

type Client added in v0.10.8

type Client struct {
	*jsonrpc2.Client
}

func NewClient added in v0.10.8

func NewClient(addr string) (*Client, error)

type Code added in v0.10.8

type Code int

type Error added in v0.10.8

type Error = jsonrpc2.Error

func InternalError added in v0.10.8

func InternalError(msg string) *Error

func InvalidParamsError added in v0.10.8

func InvalidParamsError(msg string) *Error

func InvalidRequestError added in v0.10.8

func InvalidRequestError(msg string) *Error

func MethodNotFoundError added in v0.10.8

func MethodNotFoundError(msg string) *Error

func NewError added in v0.10.8

func NewError(code Code, msg string) *Error

func NotAllowedError added in v0.10.8

func NotAllowedError(msg string) *Error

func ParseError added in v0.10.8

func ParseError(msg string) *Error

type Server

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

Server holds an RPC server that is served over HTTP

func NewServer

func NewServer(w io.Writer, config *config.Server) *Server

func (*Server) Close

func (srv *Server) Close() error

Close terminates the underlying HTTP server and listener

func (*Server) Prepare

func (srv *Server) Prepare(u *url.URL) error

Prepare injects all the data necessary for serving over the specified URL. It prepares a net.Listener over the specified URL, and registers all methods inside the given receiver. After this method is called, the Start function is ready to be called.

func (*Server) Register added in v0.10.8

func (srv *Server) Register(name string, rcvr interface{}) error

Register creates a service on the Server with the given name. The criteria of a service method is the same as defined in the net/rpc package: - the method's type is exported. - the method is exported. - the method has two arguments, both exported (or builtin) types. - the method's second argument is a pointer. - the method has return type error.

func (*Server) RegisterRestfulMap added in v0.12.0

func (srv *Server) RegisterRestfulMap(routerMap map[string]http.HandlerFunc)

RegisterRestfulMap registers all restful API functions in a map on the Server

func (*Server) Start

func (srv *Server) Start() error

Start spawns a new goroutine and listens on the configured address. Prepare should be called before calling this method

Jump to

Keyboard shortcuts

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