jsonrpc2

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateBatchRequestBody

func GenerateBatchRequestBody(requests []*json.RawMessage) (*json.RawMessage, error)

JSONRPC2のバッチリクエストBodyを作成する

func GenerateRequestBody

func GenerateRequestBody(id string, method string, params any) (*json.RawMessage, error)

JSONRPC2のリクエストBodyを作成する

Types

type Action

type Action interface {
	DecodeParams(
		ctx context.Context,
		msg *json.RawMessage,
	) (any, error)

	Exec(
		ctx context.Context,
		method string,
		params any,
	) (any, error)
}

type Client

type Client struct {
	URL      string
	Headers  map[string]string
	Requests []*ClientRequest
}

func NewClient

func NewClient(url string, headers map[string]string) *Client

func (*Client) AddRequest

func (c *Client) AddRequest(ctx context.Context, id string, method string, params any) error

JSONRPC2のリクエストを登録する

func (*Client) DoBatch

func (c *Client) DoBatch(ctx context.Context) ([]*ClientResponse, error)

JSONRPC2のバッチリクエストを行う

func (*Client) DoSingle

func (c *Client) DoSingle(ctx context.Context, method string, params any) (*json.RawMessage, *ErrorResponse, error)

JSONRPC2のシングルリクエストを行う

type ClientRequest

type ClientRequest struct {
	Version string           `json:"jsonrpc"`
	ID      string           `json:"id"`
	Method  string           `json:"method"`
	Params  *json.RawMessage `json:"params"`
}

JSONRPC2実行のリクエスト

type ClientResponse

type ClientResponse struct {
	Version string           `json:"jsonrpc"`
	ID      string           `json:"id"`
	Result  *json.RawMessage `json:"result,omitempty"`
	Error   *ErrorResponse   `json:"error,omitempty"`
}

JSONRPC2実行のレスポンス

type ErrorResponse

type ErrorResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

JSONRPC2のエラーレスポンス

type Handler

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

func NewHandler

func NewHandler() *Handler

func (*Handler) Handle

func (h *Handler) Handle(w http.ResponseWriter, r *http.Request)

JSONRPC2のリクエストをハンドルする

func (*Handler) Register

func (h *Handler) Register(method string, action Action)

JSONRPC2のリクエストを登録する

Jump to

Keyboard shortcuts

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