Documentation
¶
Index ¶
- Constants
- Variables
- func DropRequest(req *Request)
- func DropResponse(resp *Response)
- func GetParams[T any](req *Request, validators ...hvalid.Validator[T]) (T, error)
- func GinHandler(c *gin.Context)
- func Register(name string, handler Handler) error
- func SetRecoverHandler(handler func(err any))
- func StdHttpHandler(w http.ResponseWriter, r *http.Request)
- func TcpHandler(conn net.Conn)
- type Client
- type Error
- type Handler
- type HandlerFunc
- type HttpClient
- type Request
- type Response
- type TcpClient
Constants ¶
View Source
const ( // Invalid JSON was received by the server. // An error occurred on the server while parsing the JSON text. PARSE_ERR_CODE int = -32700 PARSE_ERR_MSG string = "Parse error" // The JSON sent is not a valid Request object. INVALID_REQUEST_CODE int = -32600 INVALID_REQUEST_MSG string = "Invalid request" // The method does not exist / is not available. METHOD_NOT_FOUND_CODE int = -32601 METHOD_NOT_FOUND_MSG string = "Method not found" // Invalid method parameter(s). INVALID_PARAMS_CODE int = -32602 INVALID_PARAMS_MSG string = "Invalid params" // Internal JSON-RPC error. INTERNAL_ERROR_CODE int = -32603 INTERNAL_ERROR_MSG string = "Internal error" // Reserved for implementation-defined server-errors. // Code in -32000 to -32099 SERVER_ERROR_MSG string = "Server error" )
Variables ¶
View Source
var ( ParseError = Error{ Code: PARSE_ERR_CODE, Msg: PARSE_ERR_MSG, } InvalidRequest = Error{ Code: INVALID_REQUEST_CODE, Msg: INVALID_REQUEST_MSG, } MethodNotFound = Error{ Code: METHOD_NOT_FOUND_CODE, Msg: METHOD_NOT_FOUND_MSG, } InvalidParams = Error{ Code: INVALID_PARAMS_CODE, Msg: INVALID_PARAMS_MSG, } InternalError = Error{ Code: INTERNAL_ERROR_CODE, Msg: INTERNAL_ERROR_MSG, } )
View Source
var DefaultErrorWriter io.Writer = os.Stderr
Functions ¶
func DropRequest ¶
func DropRequest(req *Request)
func DropResponse ¶
func DropResponse(resp *Response)
func GinHandler ¶
func SetRecoverHandler ¶
func SetRecoverHandler(handler func(err any))
SetRecoverHandler 设置自定义的异常处理函数
func StdHttpHandler ¶
func StdHttpHandler(w http.ResponseWriter, r *http.Request)
func TcpHandler ¶
Types ¶
type HandlerFunc ¶
func (HandlerFunc) Handle ¶
func (fn HandlerFunc) Handle(req *Request, resp *Response)
type HttpClient ¶
type HttpClient struct {
// contains filtered or unexported fields
}
func NewHttpClient ¶
func NewHttpClient(endpoint string) (*HttpClient, error)
type Request ¶
type Request struct {
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
ID int `json:"id,omitempty"`
JSONRPC string `json:"jsonrpc"`
}
func NewRequest ¶
func NewRequest() Request
Source Files
¶
Click to show internal directories.
Click to hide internal directories.