jsonrpc2

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2022 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)

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

func GenerateRequestBody

func GenerateRequestBody(id string, method string, params interface{}) (*json.RawMessage, error)

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

Types

type Action

type Action interface {
	DecodeParams(ctx context.Context, msg *json.RawMessage) (interface{}, error)
	Exec(ctx context.Context, method string, params interface{}) (interface{}, error)
}

Action ... JSORPC2アクションの定義

type Client

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

Client ... JSONRPC2のリクエストを行う

func NewClient

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

NewClient ... Clientを作成する

func (*Client) AddRequest

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

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

func (*Client) DoBatch

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

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

func (*Client) DoSingle

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

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

type ClientRequest

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

ClientRequest ... 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"`
}

ClientResponse ... JSONRPC2実行のレスポンス

type ErrorResponse

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

ErrorResponse ... JSONRPC2のエラーレスポンス

type Handler

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

Handler ... JSONRPC2に準拠したアクション

func NewHandler

func NewHandler() *Handler

NewHandler ... Handlerを作成する

func (*Handler) Handle

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

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

func (*Handler) Register

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

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

Jump to

Keyboard shortcuts

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