From 42b60fddb66f358ef1f20231b3e4ed54e84f0bd7 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Tue, 12 Oct 2021 18:30:16 +0200 Subject: [PATCH] replace gogo protobuf and switch linter --- .make/go.mk | 4 ++-- go.mod | 2 +- settings/.golangci.yml | 2 +- settings/pkg/store/filesystem/io.go | 15 ++++++++++----- store/.golangci.yaml | 2 +- webdav/pkg/dav/requests/thumbnail.go | 12 ++++++------ 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/.make/go.mk b/.make/go.mk index 9469448bd..bd3730b21 100644 --- a/.make/go.mk +++ b/.make/go.mk @@ -70,11 +70,11 @@ fmt: .PHONY: golangci-lint golangci-lint: $(GOLANGCI_LINT) - $(GOLANGCI_LINT) run -E gosec -E bodyclose -E dogsled -E durationcheck -E golint -E ifshort -E makezero -E prealloc -E predeclared --path-prefix $(NAME) + $(GOLANGCI_LINT) run -E gosec -E bodyclose -E dogsled -E durationcheck -E revive -E ifshort -E makezero -E prealloc -E predeclared --path-prefix $(NAME) .PHONY: ci-golangci-lint ci-golangci-lint: $(GOLANGCI_LINT) - $(GOLANGCI_LINT) run -E gosec -E bodyclose -E dogsled -E durationcheck -E golint -E ifshort -E makezero -E prealloc -E predeclared --path-prefix $(NAME) --timeout 10m0s --issues-exit-code 0 --out-format checkstyle > checkstyle.xml + $(GOLANGCI_LINT) run -E gosec -E bodyclose -E dogsled -E durationcheck -E revive -E ifshort -E makezero -E prealloc -E predeclared --path-prefix $(NAME) --timeout 10m0s --issues-exit-code 0 --out-format checkstyle > checkstyle.xml .PHONY: test test: diff --git a/go.mod b/go.mod index 625d8ea34..ad4e0ddd1 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,6 @@ require ( github.com/go-logr/logr v0.4.0 github.com/go-ozzo/ozzo-validation/v4 v4.3.0 github.com/gofrs/uuid v4.0.0+incompatible - github.com/gogo/protobuf v1.3.2 github.com/golang-jwt/jwt/v4 v4.0.0 github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 github.com/golang/protobuf v1.5.2 @@ -136,6 +135,7 @@ require ( github.com/go-logfmt/logfmt v0.5.0 // indirect github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect + github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/snappy v0.0.1 // indirect diff --git a/settings/.golangci.yml b/settings/.golangci.yml index 1104c30ff..4bb1586f7 100644 --- a/settings/.golangci.yml +++ b/settings/.golangci.yml @@ -26,7 +26,7 @@ linters: - unused - varcheck - depguard - - golint + - revive - goimports - unconvert - scopelint diff --git a/settings/pkg/store/filesystem/io.go b/settings/pkg/store/filesystem/io.go index 95ba87115..913589e70 100644 --- a/settings/pkg/store/filesystem/io.go +++ b/settings/pkg/store/filesystem/io.go @@ -1,9 +1,10 @@ package store import ( + "io/ioutil" "os" - "github.com/gogo/protobuf/jsonpb" + "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/proto" ) @@ -15,8 +16,12 @@ func (s Store) parseRecordFromFile(record proto.Message, filePath string) error } defer file.Close() - decoder := jsonpb.Unmarshaler{} - if err = decoder.Unmarshal(file, record); err != nil { + b, err := ioutil.ReadAll(file) + if err != nil { + return err + } + + if err := protojson.Unmarshal(b, record); err != nil { return err } return nil @@ -30,8 +35,8 @@ func (s Store) writeRecordToFile(record proto.Message, filePath string) error { } defer file.Close() - encoder := jsonpb.Marshaler{} - if err = encoder.Marshal(file, record); err != nil { + if v, err := protojson.Marshal(record); err != nil { + file.Write(v) return err } diff --git a/store/.golangci.yaml b/store/.golangci.yaml index 5957265d9..85a4bf3fe 100644 --- a/store/.golangci.yaml +++ b/store/.golangci.yaml @@ -18,7 +18,7 @@ linters: - unused - varcheck - depguard - - golint + - revive - goimports - unconvert - scopelint diff --git a/webdav/pkg/dav/requests/thumbnail.go b/webdav/pkg/dav/requests/thumbnail.go index c58da798c..4bb1fc35a 100644 --- a/webdav/pkg/dav/requests/thumbnail.go +++ b/webdav/pkg/dav/requests/thumbnail.go @@ -22,15 +22,15 @@ const ( // ThumbnailRequest combines all parameters provided when requesting a thumbnail type ThumbnailRequest struct { // The file path of the source file - Filepath string + Filepath string // The file name of the source file including the extension - Filename string + Filename string // The file extension - Extension string + Extension string // The requested width of the thumbnail - Width int32 + Width int32 // The requested height of the thumbnail - Height int32 + Height int32 // In case of a public share the public link token. PublicLinkToken string } @@ -97,7 +97,7 @@ func parseDimension(d, name string, defaultValue int64) (int64, error) { result, err := strconv.ParseInt(d, 10, 32) if err != nil || result < 1 { // The error message doesn't fit but for OC10 API compatibility reasons we have to set this. - return 0, fmt.Errorf("Cannot set %s of 0 or smaller!", name) //nolint:golint + return 0, fmt.Errorf("Cannot set %s of 0 or smaller!", name) } return result, nil }