json_rpc

package
v0.0.0-...-d5da7f7 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JSON_RPC_VERSION = "2.0"
)

Variables

This section is empty.

Functions

func CreateJSONRpcHandler

func CreateJSONRpcHandler(handlers RpcHandlers) func(w http.ResponseWriter, r *http.Request)

func CreateJSONRpcHandlerCustomUnmarshal

func CreateJSONRpcHandlerCustomUnmarshal(handlers RpcHandlers) func(w http.ResponseWriter, r *http.Request)

func CreateRawHandler

func CreateRawHandler(newContext InitialContextFactory, handle RawRequestHandler, defaultHeaders HeadersFromContext) func(w http.ResponseWriter, r *http.Request)

func MakeErrorCode

func MakeErrorCode(module int, errorCode int) int64

func ThrowError

func ThrowError(module int, errorCode int, message string, err error)

func ThrowErrorWithHttpStatus

func ThrowErrorWithHttpStatus(module int, errorCode int, httpStatus int, message string, err error)

Types

type Client

type Client interface {
	Call(url string, method string, args RPCArguments, expectedReult ResponseResultFactory) (*UntypedResponse, custom_error.CustomError)
}

func NewClient

func NewClient(httpClient *http.Client) Client

type ContextBuilder

type ContextBuilder func(ctx context.Context, request *RequestBase, rawHttpRequest *http.Request) (context.Context, ServerError)

func NewCompositeContextBuilder

func NewCompositeContextBuilder(builders []ContextBuilder) ContextBuilder

type ContextFactory

type ContextFactory func(ctx context.Context) (context.Context, context.CancelFunc)

type DecoderFactory

type DecoderFactory func(data io.Reader) *json.Decoder

type Error

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

type ErrorComposer

type ErrorComposer interface {
	MakeError(code int, err error) ServerError
}

func NewDefaultErrorComposer

func NewDefaultErrorComposer(module int, errors map[int]string) ErrorComposer

type HandlingInfo

type HandlingInfo struct {
	Handle         RequestHandler
	NewParams      RequestParamsFactory
	ComposeContext ContextBuilder
	GetHeaders     HeadersFromContext
}

type HeadersFromContext

type HeadersFromContext func(ctx context.Context) http.Header

type IDFactory

type IDFactory func() string

type InitialContextFactory

type InitialContextFactory func(ctx context.Context) (context.Context, context.CancelFunc)

type RPCArguments

type RPCArguments struct {
	Headers http.Header
	Cookies []*http.Cookie
	Data    interface{}
}

type RawRequestHandler

type RawRequestHandler func(ctx context.Context, r *http.Request) (*ResponseInfo, string)

func NewJsonRPCHandle

func NewJsonRPCHandle(getHandler func(name string) (HandlingInfo, bool), getDecoder func(data io.Reader) *json.Decoder) RawRequestHandler

func NewRawHandle

func NewRawHandle(methodHandler HandlingInfo, parse RawRequestParser) RawRequestHandler

type RequestBase

type RequestBase struct {
	Version string `json:"jsonrpc"`
	ID      string `json:"id,omitempty"`
	Method  string `json:"method"`
}

type RequestHandler

type RequestHandler func(ctx context.Context, request *RequestInfo) (*ResponseInfo, ServerError)

type RequestInfo

type RequestInfo struct {
	Headers http.Header
	Cookies []*http.Cookie
	Data    interface{}
}

type RequestParams

type RequestParams struct {
	Params interface{} `json:"params,omitempty"`
}

type RequestParamsFactory

type RequestParamsFactory func() interface{}

type ResponseBase

type ResponseBase struct {
	Version string `json:"jsonrpc"`
	ID      string `json:"id,omitempty"`
	Err     *Error `json:"error,omitempty"`
}

type ResponseInfo

type ResponseInfo struct {
	Headers http.Header
	Data    interface{}
}

type ResponseResult

type ResponseResult struct {
	Result interface{} `json:"result,omitempty"`
}

type ResponseResultFactory

type ResponseResultFactory func() interface{}

type RpcHandlers

type RpcHandlers interface {
	GetHandler(name string) (HandlingInfo, bool)
	GetHeaders(ctx context.Context) http.Header
	GetDecoder(data io.Reader) *json.Decoder
	NewContext(ctx context.Context) (context.Context, context.CancelFunc)
}

func NewCustomRpcHandlers

func NewCustomRpcHandlers(handlers map[string]HandlingInfo, defaultHeaders HeadersFromContext, contextFactory ContextFactory, decoderFactory DecoderFactory) RpcHandlers

func NewDefaultRpcHandlers

func NewDefaultRpcHandlers(handlers map[string]HandlingInfo) RpcHandlers

func NewRpcHandlers

func NewRpcHandlers(handlers map[string]HandlingInfo, defaultHeaders HeadersFromContext, timeout time.Duration) RpcHandlers

type ServerError

type ServerError interface {
	GetCode() int64
	GetMessage() string
	GetData() *string
	GetStatus() int
	ToError() *Error
	Unwrap() error
}

func MakeError

func MakeError(module int, errorCode int, message string, err error) ServerError

func MakeErrorWithCode

func MakeErrorWithCode(code int64, message string, err error) ServerError

func MakeErrorWithHttpStatus

func MakeErrorWithHttpStatus(module int, errorCode int, httpStatus int, message string, err error) ServerError

type UnknownErrorData

type UnknownErrorData struct {
	CallStack     string      `json:"call_stack"`
	OriginalError interface{} `json:"original_error"`
}

type UntypedRequest

type UntypedRequest struct {
	RequestBase
	RequestParams
}

type UntypedResponse

type UntypedResponse struct {
	ResponseBase
	ResponseResult
}

Jump to

Keyboard shortcuts

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