replace gogo protobuf and switch linter

This commit is contained in:
Willy Kloucek
2021-10-12 18:30:16 +02:00
parent cbac7e0052
commit 42b60fddb6
6 changed files with 21 additions and 16 deletions

View File

@@ -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:

2
go.mod
View File

@@ -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

View File

@@ -26,7 +26,7 @@ linters:
- unused
- varcheck
- depguard
- golint
- revive
- goimports
- unconvert
- scopelint

View File

@@ -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
}

View File

@@ -18,7 +18,7 @@ linters:
- unused
- varcheck
- depguard
- golint
- revive
- goimports
- unconvert
- scopelint

View File

@@ -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
}