From bbb4ce586f580399c4ef1b0dadced57b4782e3e6 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Sun, 28 Mar 2021 20:42:11 +0800 Subject: [PATCH] fix golint issues (#584) --- core/mapping/utils.go | 44 ++++++++++++++++++----------- zrpc/internal/mock/depositserver.go | 2 ++ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/core/mapping/utils.go b/core/mapping/utils.go index 813c93e9..67f59eff 100644 --- a/core/mapping/utils.go +++ b/core/mapping/utils.go @@ -170,6 +170,28 @@ func implicitValueRequiredStruct(tag string, tp reflect.Type) (bool, error) { return false, nil } +func isLeftInclude(b byte) (bool, error) { + switch b { + case '[': + return true, nil + case '(': + return false, nil + default: + return false, errNumberRange + } +} + +func isRightInclude(b byte) (bool, error) { + switch b { + case ']': + return true, nil + case ')': + return false, nil + default: + return false, errNumberRange + } +} + func maybeNewValue(field reflect.StructField, value reflect.Value) { if field.Type.Kind() == reflect.Ptr && value.IsNil() { value.Set(reflect.New(value.Type().Elem())) @@ -211,14 +233,9 @@ func parseNumberRange(str string) (*numberRange, error) { return nil, errNumberRange } - var leftInclude bool - switch str[0] { - case '[': - leftInclude = true - case '(': - leftInclude = false - default: - return nil, errNumberRange + leftInclude, err := isLeftInclude(str[0]) + if err != nil { + return nil, err } str = str[1:] @@ -226,14 +243,9 @@ func parseNumberRange(str string) (*numberRange, error) { return nil, errNumberRange } - var rightInclude bool - switch str[len(str)-1] { - case ']': - rightInclude = true - case ')': - rightInclude = false - default: - return nil, errNumberRange + rightInclude, err := isRightInclude(str[len(str)-1]) + if err != nil { + return nil, err } str = str[:len(str)-1] diff --git a/zrpc/internal/mock/depositserver.go b/zrpc/internal/mock/depositserver.go index 8b33523a..d9961865 100644 --- a/zrpc/internal/mock/depositserver.go +++ b/zrpc/internal/mock/depositserver.go @@ -7,9 +7,11 @@ import ( "google.golang.org/grpc/status" ) +// DespositServer is used for mocking. type DepositServer struct { } +// Deposit handles the deposit requests. func (*DepositServer) Deposit(ctx context.Context, req *DepositRequest) (*DepositResponse, error) { if req.GetAmount() < 0 { return nil, status.Errorf(codes.InvalidArgument, "cannot deposit %v", req.GetAmount())