jsonrpc

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2021 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var JSONRPCRequestForm = forms.Form{
	Fields: []forms.Field{
		{
			Name: "jsonrpc",
			Validators: []forms.Validator{
				forms.IsString{},
				forms.IsIn{

					Choices: []interface{}{"2.0"},
				},
			},
		},
		{
			Name: "method",
			Validators: []forms.Validator{
				forms.IsString{
					MinLength: 1,
					MaxLength: 100,
				},
			},
		},
		{
			Name: "params",
			Validators: []forms.Validator{

				forms.IsStringMap{},
			},
		},
		{
			Name: "id",
			Validators: []forms.Validator{

				forms.IsOptional{},

				forms.Or{
					Options: [][]forms.Validator{
						{

							forms.IsString{
								MinLength: 1,
								MaxLength: 100,
							},
						},
						{

							forms.IsInteger{
								HasMin: true,
								HasMax: true,
								Min:    -2147483648,
								Max:    2147483647,
							},
						},
					},
				},
			},
		},
	},
}

Functions

func Cors

func Cors(settings *services.CorsSettings, defaultRoute bool) http.Handler

func CorsFromEverywhere

func CorsFromEverywhere(settings *services.CorsSettings) http.Handler

func ExtractJSONRequest

func ExtractJSONRequest(c *http.Context)

extracts the request data from known limitations: very large numerical ID values will be truncated due to the fact that Golang converts JSON numbers to float64 values...

Types

type Client

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

func MakeClient

func MakeClient(endpoint string) *Client

func (*Client) Call

func (c *Client) Call(request *Request) (*Response, error)

type Context

type Context struct {
	Request *Request
}

func (*Context) Acknowledge

func (c *Context) Acknowledge() services.Response

func (*Context) Error

func (c *Context) Error(code int, message string, data interface{}) services.Response

func (*Context) InternalError

func (c *Context) InternalError() services.Response

func (*Context) InvalidParams

func (c *Context) InvalidParams(err error) services.Response

func (*Context) MethodNotFound

func (c *Context) MethodNotFound() services.Response

func (*Context) Nil

func (c *Context) Nil() services.Response

func (*Context) NotFound

func (c *Context) NotFound() services.Response

func (*Context) Params added in v0.0.6

func (c *Context) Params() map[string]interface{}

func (*Context) Result

func (c *Context) Result(data interface{}) services.Response

type Error

type Error struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

type Handler

type Handler func(*Context) *Response

func MethodsHandler

func MethodsHandler(methods map[string]*Method) (Handler, error)

type JSONRPCServer

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

func MakeJSONRPCServer

func MakeJSONRPCServer(settings *services.JSONRPCServerSettings, handler Handler, metricsPrefix string, httpServer *http.HTTPServer) (*JSONRPCServer, error)

func (*JSONRPCServer) JSONRPC

func (s *JSONRPCServer) JSONRPC(handler Handler) http.Handler

func (*JSONRPCServer) Start

func (s *JSONRPCServer) Start() error

func (*JSONRPCServer) Stop

func (s *JSONRPCServer) Stop() error

type Method

type Method struct {
	Form    *forms.Form
	Handler interface{}
}

type Request

type Request struct {
	JSONRPC string                 `json:"jsonrpc"`
	Method  string                 `json:"method"`
	Params  map[string]interface{} `json:"params"`
	ID      string                 `json:"id"`
}

func MakeRequest

func MakeRequest(method, id string, params map[string]interface{}) *Request

type Response

type Response struct {
	JSONRPC string      `json:"jsonrpc"`
	Result  interface{} `json:"result,omitempty"`
	Error   *Error      `json:"error,omitempty"`
	ID      interface{} `json:"id"`
}

func (*Response) AsJSON

func (r *Response) AsJSON() string

Jump to

Keyboard shortcuts

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