diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc4e0edf2..2faebe5f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,21 @@ jobs: - name: Test run: make test + lint: + runs-on: ubuntu-20.04 + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.14.x + - uses: actions/checkout@v2 + - name: Install golangci-lint + run: | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.38.0 + golangci-lint --version + - name: Lint + run: make lint + generated-files-integrity: runs-on: ubuntu-20.04 diff --git a/code/go/0chain.net/blobbercore/allocation/allocationchange.go b/code/go/0chain.net/blobbercore/allocation/allocationchange.go index 9cc289411..3f3a117b6 100644 --- a/code/go/0chain.net/blobbercore/allocation/allocationchange.go +++ b/code/go/0chain.net/blobbercore/allocation/allocationchange.go @@ -169,5 +169,4 @@ func (a *AllocationChangeCollector) DeleteChanges(ctx context.Context) { logging.Logger.Error("AllocationChangeProcessor_DeleteTempFile", zap.Error(err)) } } - return } diff --git a/code/go/0chain.net/blobbercore/handler/grpcMiddleware.go b/code/go/0chain.net/blobbercore/handler/grpcMiddleware.go index f24dd125e..867b8b271 100644 --- a/code/go/0chain.net/blobbercore/handler/grpcMiddleware.go +++ b/code/go/0chain.net/blobbercore/handler/grpcMiddleware.go @@ -45,7 +45,9 @@ func unaryDatabaseTransactionInjector() grpc.UnaryServerInterceptor { func unaryTimeoutInterceptor() grpc.UnaryServerInterceptor { return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { deadline := time.Now().Add(time.Duration(TIMEOUT_SECONDS * time.Second)) - ctx, _ = context.WithDeadline(ctx, deadline) + ctx, canceler := context.WithDeadline(ctx, deadline) + defer canceler() + return handler(ctx, req) } } diff --git a/code/go/0chain.net/blobbercore/handler/handler.go b/code/go/0chain.net/blobbercore/handler/handler.go index 059106fad..49da5ac50 100644 --- a/code/go/0chain.net/blobbercore/handler/handler.go +++ b/code/go/0chain.net/blobbercore/handler/handler.go @@ -3,17 +3,18 @@ package handler import ( - "0chain.net/blobbercore/config" - "0chain.net/blobbercore/constants" - "0chain.net/blobbercore/datastore" - "0chain.net/blobbercore/stats" - "0chain.net/core/common" "context" "net/http" "os" "runtime/pprof" "time" + "0chain.net/blobbercore/config" + "0chain.net/blobbercore/constants" + "0chain.net/blobbercore/datastore" + "0chain.net/blobbercore/stats" + "0chain.net/core/common" + . "0chain.net/core/logging" "go.uber.org/zap" @@ -204,7 +205,9 @@ func CommitHandler(ctx context.Context, r *http.Request) (interface{}, error) { } func ReferencePathHandler(ctx context.Context, r *http.Request) (interface{}, error) { - ctx, _ = context.WithTimeout(ctx, time.Second*10) + ctx, canceler := context.WithTimeout(ctx, time.Second*10) + defer canceler() + ctx = setupHandlerContext(ctx, r) response, err := storageHandler.GetReferencePath(ctx, r) diff --git a/code/go/0chain.net/blobbercore/handler/helper.go b/code/go/0chain.net/blobbercore/handler/helper.go index 1bdd70e80..b412aa718 100644 --- a/code/go/0chain.net/blobbercore/handler/helper.go +++ b/code/go/0chain.net/blobbercore/handler/helper.go @@ -30,7 +30,7 @@ func RegisterGRPCServices(r *mux.Router, server *grpc.Server) { blobberService := newGRPCBlobberService(&storageHandler, packHandler) mux := runtime.NewServeMux() blobbergrpc.RegisterBlobberServer(server, blobberService) - blobbergrpc.RegisterBlobberHandlerServer(context.Background(), mux, blobberService) + _ = blobbergrpc.RegisterBlobberHandlerServer(context.Background(), mux, blobberService) r.PathPrefix("/").Handler(mux) } diff --git a/code/go/0chain.net/blobbercore/handler/storage_handler.go b/code/go/0chain.net/blobbercore/handler/storage_handler.go index 075df3ed9..92b924484 100644 --- a/code/go/0chain.net/blobbercore/handler/storage_handler.go +++ b/code/go/0chain.net/blobbercore/handler/storage_handler.go @@ -1,14 +1,15 @@ package handler import ( - "0chain.net/core/encryption" "context" "encoding/json" - "github.com/gorilla/mux" "net/http" "strconv" "strings" + "0chain.net/core/encryption" + "github.com/gorilla/mux" + "0chain.net/blobbercore/stats" "go.uber.org/zap" @@ -537,7 +538,6 @@ func (fsh *StorageHandler) getReferencePath(ctx context.Context, r *http.Request } resCh <- &refPathResult - return } func (fsh *StorageHandler) GetObjectPath(ctx context.Context, r *http.Request) (*ObjectPathResult, error) { diff --git a/code/go/0chain.net/blobbercore/util/json.go b/code/go/0chain.net/blobbercore/util/json.go index 753023c2c..d35570024 100644 --- a/code/go/0chain.net/blobbercore/util/json.go +++ b/code/go/0chain.net/blobbercore/util/json.go @@ -2,9 +2,8 @@ package util import ( "fmt" - "strings" "reflect" - "errors" + "strings" ) // Validate unmarshalled data with tag-based rules @@ -20,7 +19,7 @@ func UnmarshalValidation(v interface{}) error { if strings.Contains(validation, "required") && fields.Field(i).IsZero() { // todo: better try this first: // jsonFieldName := fields.Type().Field(i).Tag.Get("json") - return errors.New(fmt.Sprintf("The '%s' field is required", fields.Type().Field(i).Name)) + return fmt.Errorf("The '%s' field is required", fields.Type().Field(i).Name) } }