Documentation ¶
Index ¶
- Constants
- func CreateJSONRpcHandler(handlers RpcHandlers) func(w http.ResponseWriter, r *http.Request)
- func CreateJSONRpcHandlerCustomUnmarshal(handlers RpcHandlers) func(w http.ResponseWriter, r *http.Request)
- func CreateRawHandler(newContext InitialContextFactory, handle RawRequestHandler, ...) func(w http.ResponseWriter, r *http.Request)
- func MakeErrorCode(module int, errorCode int) int64
- func ThrowError(module int, errorCode int, message string, err error)
- func ThrowErrorWithHttpStatus(module int, errorCode int, httpStatus int, message string, err error)
- type Client
- type ContextBuilder
- type ContextFactory
- type DecoderFactory
- type Error
- type ErrorComposer
- type HandlingInfo
- type HeadersFromContext
- type IDFactory
- type InitialContextFactory
- type RPCArguments
- type RawRequestHandler
- type RawRequestParser
- type RequestBase
- type RequestHandler
- type RequestInfo
- type RequestParams
- type RequestParamsFactory
- type ResponseBase
- type ResponseInfo
- type ResponseResult
- type ResponseResultFactory
- type RpcHandlers
- type ServerError
- type UnknownErrorData
- type UntypedRequest
- type UntypedResponse
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 ¶
Types ¶
type Client ¶
type Client interface {
Call(url string, method string, args RPCArguments, expectedReult ResponseResultFactory) (*UntypedResponse, custom_error.CustomError)
}
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 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 InitialContextFactory ¶
type RPCArguments ¶
type RawRequestHandler ¶
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 RawRequestParser ¶
type RawRequestParser func(ctx context.Context, r *http.Request) (context.Context, *RequestBase, *RequestParams, custom_error.CustomError)
type RequestBase ¶
type RequestHandler ¶
type RequestHandler func(ctx context.Context, request *RequestInfo) (*ResponseInfo, ServerError)
type RequestInfo ¶
type RequestParams ¶
type RequestParams struct {
Params interface{} `json:"params,omitempty"`
}
type RequestParamsFactory ¶
type RequestParamsFactory func() interface{}
type ResponseBase ¶
type ResponseInfo ¶
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 MakeErrorWithCode ¶
func MakeErrorWithCode(code int64, message string, err error) ServerError
func MakeErrorWithHttpStatus ¶
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 }
Click to show internal directories.
Click to hide internal directories.