more lint fixes
This commit is contained in:
parent
661c7d6339
commit
0f8f61fc7b
@ -5,6 +5,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-lotus/rpclib"
|
"github.com/filecoin-project/go-lotus/rpclib"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewRPC creates a new http jsonrpc client.
|
||||||
func NewRPC(addr string) api.API {
|
func NewRPC(addr string) api.API {
|
||||||
var res api.Struct
|
var res api.Struct
|
||||||
rpclib.NewClient(addr, "Filecoin", &res.Internal)
|
rpclib.NewClient(addr, "Filecoin", &res.Internal)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
|
// Version is the local build version, set by build system
|
||||||
const Version = "0.0.0"
|
const Version = "0.0.0"
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"go.uber.org/fx"
|
"go.uber.org/fx"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// MetricsCtx is a context wrapper with metrics
|
||||||
type MetricsCtx context.Context
|
type MetricsCtx context.Context
|
||||||
|
|
||||||
// LifecycleCtx creates a context which will be cancelled when lifecycle stops
|
// LifecycleCtx creates a context which will be cancelled when lifecycle stops
|
||||||
|
@ -16,6 +16,7 @@ var (
|
|||||||
contextType = reflect.TypeOf(new(context.Context)).Elem()
|
contextType = reflect.TypeOf(new(context.Context)).Elem()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrClient is an error which occured on the client side the library
|
||||||
type ErrClient struct {
|
type ErrClient struct {
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
@ -24,6 +25,7 @@ func (e *ErrClient) Error() string {
|
|||||||
return fmt.Sprintf("RPC client error: %s", e.err)
|
return fmt.Sprintf("RPC client error: %s", e.err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the actual error
|
||||||
func (e *ErrClient) Unwrap(err error) error {
|
func (e *ErrClient) Unwrap(err error) error {
|
||||||
return e.err
|
return e.err
|
||||||
}
|
}
|
||||||
@ -41,6 +43,11 @@ type clientResponse struct {
|
|||||||
Error *respError `json:"error,omitempty"`
|
Error *respError `json:"error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewClient creates new josnrpc 2.0 client
|
||||||
|
//
|
||||||
|
// handler must be pointer to a struct with function fields
|
||||||
|
//
|
||||||
|
// TODO: Example
|
||||||
func NewClient(addr string, namespace string, handler interface{}) {
|
func NewClient(addr string, namespace string, handler interface{}) {
|
||||||
htyp := reflect.TypeOf(handler)
|
htyp := reflect.TypeOf(handler)
|
||||||
if htyp.Kind() != reflect.Ptr {
|
if htyp.Kind() != reflect.Ptr {
|
||||||
|
@ -10,10 +10,10 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
rpcParseError = -32700
|
rpcParseError = -32700
|
||||||
rpcInvalidRequest = -32600
|
// rpcInvalidRequest = -32600
|
||||||
rpcMethodNotFound = -32601
|
rpcMethodNotFound = -32601
|
||||||
rpcInvalidParams = -32602
|
rpcInvalidParams = -32602
|
||||||
rpcInternalError = -32603
|
// rpcInternalError = -32603
|
||||||
)
|
)
|
||||||
|
|
||||||
type rpcHandler struct {
|
type rpcHandler struct {
|
||||||
@ -29,10 +29,12 @@ type rpcHandler struct {
|
|||||||
valOut int
|
valOut int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RPCServer provides a jsonrpc 2.0 http server handler
|
||||||
type RPCServer struct {
|
type RPCServer struct {
|
||||||
methods map[string]rpcHandler
|
methods map[string]rpcHandler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewServer creates new RPCServer instance
|
||||||
func NewServer() *RPCServer {
|
func NewServer() *RPCServer {
|
||||||
return &RPCServer{
|
return &RPCServer{
|
||||||
methods: map[string]rpcHandler{},
|
methods: map[string]rpcHandler{},
|
||||||
@ -163,6 +165,9 @@ func (s *RPCServer) rpcError(w http.ResponseWriter, req *request, code int, err
|
|||||||
_ = json.NewEncoder(w).Encode(resp)
|
_ = json.NewEncoder(w).Encode(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register registers new RPC handler
|
||||||
|
//
|
||||||
|
// Handler is any value with methods defined
|
||||||
func (s *RPCServer) Register(namespace string, r interface{}) {
|
func (s *RPCServer) Register(namespace string, r interface{}) {
|
||||||
val := reflect.ValueOf(r)
|
val := reflect.ValueOf(r)
|
||||||
//TODO: expect ptr
|
//TODO: expect ptr
|
||||||
|
Loading…
Reference in New Issue
Block a user