fix linter

This commit is contained in:
A.Unger
2020-07-15 15:31:27 +02:00
parent 57ac6b063a
commit 117b376509
8 changed files with 41 additions and 45 deletions

View File

@@ -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',
],
},
{

29
.golangci.yaml Normal file
View File

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

View File

@@ -10,4 +10,4 @@ func main() {
if err := command.Execute(); err != nil {
os.Exit(1)
}
}
}

2
go.sum
View File

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

View File

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

View File

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

View File

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

View File

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