Documentation
¶
Index ¶
- Constants
- func ErrInternalJSON() []byte
- func ErrInvalidParamsJSON() []byte
- func ErrInvalidRequestJSON() []byte
- func ErrMaxBatchRequestsJSON() []byte
- func ErrMethodNotFoundJSON() []byte
- func ErrParseJSON() []byte
- type Error
- type Handler
- type JRPCError
- type MiddlewareFunc
- type Options
- type RequestCtx
- type Result
- type Server
- type Service
Constants ¶
const ( // ErrorCodeParse Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text. ErrorCodeParse int = -32700 // ErrorCodeInvalidRequest The JSON sent is not a valid Request object. ErrorCodeInvalidRequest int = -32600 // ErrorCodeMethodNotFound The method does not exist / is not available. ErrorCodeMethodNotFound int = -32601 // ErrorCodeInvalidParams Invalid method parameter(s). ErrorCodeInvalidParams int = -32602 // ErrorCodeInternal Internal JSON-RPC error. ErrorCodeInternal int = -32603 // ErrorMaxBatchRequests Max requests in batch. ErrorMaxBatchRequests int = -32604 )
const (
Version = "2.0"
)
Variables ¶
This section is empty.
Functions ¶
func ErrInternalJSON ¶ added in v0.2.0
func ErrInternalJSON() []byte
ErrInternalJSON return json internal error.
func ErrInvalidParamsJSON ¶ added in v0.2.0
func ErrInvalidParamsJSON() []byte
ErrInvalidParamsJSON return json invalid params error.
func ErrInvalidRequestJSON ¶ added in v0.2.0
func ErrInvalidRequestJSON() []byte
ErrInvalidRequestJSON return json invalid request error.
func ErrMaxBatchRequestsJSON ¶ added in v0.2.0
func ErrMaxBatchRequestsJSON() []byte
ErrMaxBatchRequestsJSON return json max requests length in batch error.
func ErrMethodNotFoundJSON ¶ added in v0.2.0
func ErrMethodNotFoundJSON() []byte
ErrMethodNotFoundJSON return json method not found error.
func ErrParseJSON ¶ added in v0.2.0
func ErrParseJSON() []byte
ErrParseJSON return json parse error.
Types ¶
type Handler ¶
type Handler func(*RequestCtx) (Result, Error)
type JRPCError ¶ added in v0.2.0
type JRPCError struct { Code int `json:"code"` Message string `json:"message"` Data interface{} `json:"data,omitempty"` }
JRPCError is a wrapper for a JSON interface value.
func ErrInvalidParams ¶
func ErrInvalidParams() *JRPCError
ErrInvalidParams returns invalid params error.
func ErrInvalidRequest ¶
func ErrInvalidRequest() *JRPCError
ErrInvalidRequest returns invalid request error.
func ErrMaxBatchRequests ¶
func ErrMaxBatchRequests() *JRPCError
ErrMaxBatchRequests returns max requests length in batch error.
func ErrMethodNotFound ¶
func ErrMethodNotFound() *JRPCError
ErrMethodNotFound returns method not found error.
type MiddlewareFunc ¶
type RequestCtx ¶
type RequestCtx struct { R *http.Request ID string Params []byte Keys map[string]interface{} // contains filtered or unexported fields }
func (*RequestCtx) Get ¶
func (ctx *RequestCtx) Get(key string) (value interface{}, exists bool)
Get returns the value for the given key,
func (*RequestCtx) GetParams ¶ added in v0.2.0
func (ctx *RequestCtx) GetParams(v interface{}) error
GetParams decode params with standard encoding/json package.
func (*RequestCtx) Result ¶ added in v0.2.0
func (ctx *RequestCtx) Result(v interface{}) (Result, Error)
Result encode json with standard encoding/json package.
func (*RequestCtx) Set ¶
func (ctx *RequestCtx) Set(key string, value interface{})
Set store a new key/value pair.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) GetService ¶ added in v0.2.0
GetService get registered service by method name.
func (*Server) ServeHTTP ¶
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP process incoming requests.
func (*Server) Use ¶
func (s *Server) Use(middlewares ...MiddlewareFunc)
Use appends a middleware handler to server. This middleware call for each service request.