more lint fixes

This commit is contained in:
Łukasz Magiera 2019-07-02 19:45:03 +02:00
parent 661c7d6339
commit 0f8f61fc7b
5 changed files with 17 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import (
"github.com/filecoin-project/go-lotus/rpclib"
)
// NewRPC creates a new http jsonrpc client.
func NewRPC(addr string) api.API {
var res api.Struct
rpclib.NewClient(addr, "Filecoin", &res.Internal)

View File

@ -1,3 +1,4 @@
package build
// Version is the local build version, set by build system
const Version = "0.0.0"

View File

@ -6,6 +6,7 @@ import (
"go.uber.org/fx"
)
// MetricsCtx is a context wrapper with metrics
type MetricsCtx context.Context
// LifecycleCtx creates a context which will be cancelled when lifecycle stops

View File

@ -16,6 +16,7 @@ var (
contextType = reflect.TypeOf(new(context.Context)).Elem()
)
// ErrClient is an error which occured on the client side the library
type ErrClient struct {
err error
}
@ -24,6 +25,7 @@ func (e *ErrClient) Error() string {
return fmt.Sprintf("RPC client error: %s", e.err)
}
// Unwrap unwraps the actual error
func (e *ErrClient) Unwrap(err error) error {
return e.err
}
@ -41,6 +43,11 @@ type clientResponse struct {
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{}) {
htyp := reflect.TypeOf(handler)
if htyp.Kind() != reflect.Ptr {

View File

@ -10,10 +10,10 @@ import (
const (
rpcParseError = -32700
rpcInvalidRequest = -32600
// rpcInvalidRequest = -32600
rpcMethodNotFound = -32601
rpcInvalidParams = -32602
rpcInternalError = -32603
// rpcInternalError = -32603
)
type rpcHandler struct {
@ -29,10 +29,12 @@ type rpcHandler struct {
valOut int
}
// RPCServer provides a jsonrpc 2.0 http server handler
type RPCServer struct {
methods map[string]rpcHandler
}
// NewServer creates new RPCServer instance
func NewServer() *RPCServer {
return &RPCServer{
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)
}
// Register registers new RPC handler
//
// Handler is any value with methods defined
func (s *RPCServer) Register(namespace string, r interface{}) {
val := reflect.ValueOf(r)
//TODO: expect ptr