Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrorParseError = &Error{-32700, "Parse error", nil} ErrInvalidRequest = &Error{-32600, "Invalid Request", nil} ErrMethodNotFound = &Error{-32601, "Method not found", nil} ErrInvalidParams = &Error{-32602, "Invalid params", nil} ErrInternalError = &Error{-32603, "Internal error", nil} )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a JSON-RPC Client.
func NewClient ¶
NewClient returns a new Client to handle requests to a JSON-RPC server. TODO: support custom httpClients
type Error ¶
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"` // defined by the server
}
Error represents a JSON-RPC error, it implements the error interface.
type Response ¶ added in v0.1.3
type Response struct {
// contains filtered or unexported fields
}
Response represents the Response from a JSON-RPC request.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents a JSON-RPC server.
Example ¶
package main
import (
"context"
"net/http"
"github.com/echovl/jsonrpc"
)
type Version struct {
Tag string
}
func main() {
server := jsonrpc.NewServer()
err := server.HandleFunc("version", func(ctx context.Context) (Version, error) {
return Version{"1.0.0"}, nil
})
if err != nil {
panic(err)
}
http.Handle("/api", server)
http.ListenAndServe(":4545", nil)
}
func (*Server) HandleFunc ¶
HandleFunc registers the handle function for the given JSON-RPC method.
Click to show internal directories.
Click to hide internal directories.