diff --git a/.drone.star b/.drone.star index a204a15edb..e439f9d9be 100644 --- a/.drone.star +++ b/.drone.star @@ -60,32 +60,11 @@ def testing(ctx): }, ], }, - { - 'name': 'staticcheck', - 'image': 'webhippie/golang:1.13', - 'pull': 'always', - 'commands': [ - 'make staticcheck', - ], - 'volumes': [ - { - 'name': 'gopath', - 'path': '/srv/app', - }, - ], - }, { 'name': 'lint', - 'image': 'webhippie/golang:1.13', - 'pull': 'always', + 'image': 'golangci/golangci-lint:v1.26', 'commands': [ - 'make lint', - ], - 'volumes': [ - { - 'name': 'gopath', - 'path': '/srv/app', - }, + 'golangci-lint run --timeout 2m0s', ], }, { diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000000..5957265d95 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,29 @@ +issues: + exclude-rules: + - path: pkg/proto/v0 + text: "SA1019:" + linters: + - staticcheck +linters: + enable: + - bodyclose + - deadcode + - errcheck + - gosimple + - govet + - ineffassign + - staticcheck + - structcheck + - typecheck + - unused + - varcheck + - depguard + - golint + - goimports + - unconvert + - scopelint + - maligned + - misspell + - gocritic + - prealloc + #- gosec diff --git a/cmd/ocis-store/main.go b/cmd/ocis-store/main.go index 30987cdd47..0d20241b8d 100644 --- a/cmd/ocis-store/main.go +++ b/cmd/ocis-store/main.go @@ -10,4 +10,4 @@ func main() { if err := command.Execute(); err != nil { os.Exit(1) } -} \ No newline at end of file +} diff --git a/go.sum b/go.sum index 033a03af2c..8999a8faf6 100644 --- a/go.sum +++ b/go.sum @@ -935,9 +935,11 @@ golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20191216173652-a0e659d51361 h1:RIIXAeV6GvDBuADKumTODatUqANFZ+5BPMnzsy4hulY= golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/tools v0.0.0-20200526224456-8b020aee10d2 h1:21BqcH/onxtGHn1A2GDOJjZnbt4Nlez629S3eaR+eYs= golang.org/x/tools v0.0.0-20200526224456-8b020aee10d2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= diff --git a/pkg/command/server.go b/pkg/command/server.go index b2ede247d3..3964f135b2 100644 --- a/pkg/command/server.go +++ b/pkg/command/server.go @@ -139,9 +139,7 @@ func Server(cfg *config.Config) *cli.Command { grpc.Flags(flagset.ServerWithConfig(config.New())), ) - gr.Add(func() error { - return server.Run() - }, func(_ error) { + gr.Add(server.Run, func(_ error) { logger.Info(). Str("server", "grpc"). Msg("Shutting down server") @@ -166,9 +164,7 @@ func Server(cfg *config.Config) *cli.Command { return err } - gr.Add(func() error { - return server.ListenAndServe() - }, func(_ error) { + gr.Add(server.ListenAndServe, func(_ error) { ctx, timeout := context.WithTimeout(ctx, 5*time.Second) defer timeout() diff --git a/pkg/server/debug/option.go b/pkg/server/debug/option.go index 23313804d5..6c57e20903 100644 --- a/pkg/server/debug/option.go +++ b/pkg/server/debug/option.go @@ -3,8 +3,8 @@ package debug import ( "context" - "github.com/owncloud/ocis-store/pkg/config" "github.com/owncloud/ocis-pkg/v2/log" + "github.com/owncloud/ocis-store/pkg/config" ) // Option defines a single option function. diff --git a/pkg/server/debug/server.go b/pkg/server/debug/server.go index 64dd669f88..0528264e2a 100644 --- a/pkg/server/debug/server.go +++ b/pkg/server/debug/server.go @@ -4,9 +4,9 @@ import ( "io" "net/http" + "github.com/owncloud/ocis-pkg/v2/service/debug" "github.com/owncloud/ocis-store/pkg/config" "github.com/owncloud/ocis-store/pkg/version" - "github.com/owncloud/ocis-pkg/v2/service/debug" ) // Server initializes the debug service and server. @@ -34,7 +34,7 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) { // TODO(tboerger): check if services are up and running - io.WriteString(w, http.StatusText(http.StatusOK)) + _, _ = io.WriteString(w, http.StatusText(http.StatusOK)) } } @@ -46,6 +46,6 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) { // TODO(tboerger): check if services are up and running - io.WriteString(w, http.StatusText(http.StatusOK)) + _, _ = io.WriteString(w, http.StatusText(http.StatusOK)) } } diff --git a/pkg/service/v0/service.go b/pkg/service/v0/service.go index 772569b672..964194459c 100644 --- a/pkg/service/v0/service.go +++ b/pkg/service/v0/service.go @@ -2,12 +2,10 @@ package service import ( "context" - "errors" "fmt" "io/ioutil" "os" "path/filepath" - "strings" "github.com/blevesearch/bleve" "github.com/blevesearch/bleve/analysis/analyzer/keyword" @@ -40,7 +38,7 @@ func New(opts ...Option) (s *Service, err error) { } indexMapping := bleve.NewIndexMapping() - // keep all symbols in terms to allow exact maching, eg. emails + // keep all symbols in terms to allow exact matching, eg. emails indexMapping.DefaultAnalyzer = keyword.Name indexMapping.TypeField = "bleve_type" @@ -73,14 +71,6 @@ type Service struct { index bleve.Index } -func cleanupID(id string) (string, error) { - id = filepath.Clean(id) - if id == "." || strings.Contains(id, "/") { - return "", errors.New("invalid id " + id) - } - return id, nil -} - // Read implements the StoreHandler interface. func (s *Service) Read(c context.Context, rreq *proto.ReadRequest, rres *proto.ReadResponse) error { file := filepath.Join(s.Config.Datapath, "databases", rreq.Options.Database, rreq.Options.Table, rreq.Key)