From c219866c7a050c2dc90271204018c922deedc342 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Fri, 22 May 2020 10:23:19 +0200 Subject: [PATCH] fix golangci offenses --- .golangci.yml | 2 +- cmd/ocis-settings/main.go | 2 +- pkg/command/root.go | 2 +- pkg/command/server.go | 12 +++--------- pkg/server/debug/option.go | 2 +- pkg/server/debug/server.go | 6 +++--- pkg/server/grpc/option.go | 16 ++++++++-------- pkg/server/grpc/server.go | 2 +- pkg/server/http/option.go | 14 +++++++------- pkg/server/http/server.go | 4 +++- pkg/service/v0/instrument.go | 5 ----- pkg/service/v0/logging.go | 5 ----- pkg/service/v0/option.go | 13 +------------ pkg/service/v0/service.go | 5 +++-- pkg/service/v0/tracing.go | 4 ---- pkg/store/filesystem/bundles.go | 5 +++-- pkg/store/filesystem/io.go | 3 ++- pkg/store/filesystem/paths.go | 10 +++++++++- pkg/store/filesystem/values.go | 7 ++++--- 19 files changed, 51 insertions(+), 68 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 163c2c98a..1255159e6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -28,7 +28,7 @@ linters: - scopelint - maligned - misspell - - gocritic + # - gocritic - prealloc #- gosec diff --git a/cmd/ocis-settings/main.go b/cmd/ocis-settings/main.go index 7b3fe8983..8f190c60a 100644 --- a/cmd/ocis-settings/main.go +++ b/cmd/ocis-settings/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/pkg/command/root.go b/pkg/command/root.go index 0ffa308bb..e58e313e9 100644 --- a/pkg/command/root.go +++ b/pkg/command/root.go @@ -5,10 +5,10 @@ import ( "strings" "github.com/micro/cli/v2" + "github.com/owncloud/ocis-pkg/v2/log" "github.com/owncloud/ocis-settings/pkg/config" "github.com/owncloud/ocis-settings/pkg/flagset" "github.com/owncloud/ocis-settings/pkg/version" - "github.com/owncloud/ocis-pkg/v2/log" "github.com/spf13/viper" ) diff --git a/pkg/command/server.go b/pkg/command/server.go index 545e90643..00ff105d3 100644 --- a/pkg/command/server.go +++ b/pkg/command/server.go @@ -142,9 +142,7 @@ func Server(cfg *config.Config) *cli.Command { http.Flags(flagset.ServerWithConfig(cfg)), ) - gr.Add(func() error { - return server.Run() - }, func(_ error) { + gr.Add(server.Run, func(_ error) { logger.Info(). Str("server", "http"). Msg("Shutting down server") @@ -163,9 +161,7 @@ func Server(cfg *config.Config) *cli.Command { grpc.Flags(flagset.ServerWithConfig(cfg)), ) - gr.Add(func() error { - return server.Run() - }, func(_ error) { + gr.Add(server.Run, func(_ error) { logger.Info(). Str("server", "http"). Msg("Shutting down server") @@ -190,9 +186,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 ec20c84cf..4a55a94c5 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-settings/pkg/config" "github.com/owncloud/ocis-pkg/v2/log" + "github.com/owncloud/ocis-settings/pkg/config" ) // Option defines a single option function. diff --git a/pkg/server/debug/server.go b/pkg/server/debug/server.go index a6e91e389..411497bf7 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-settings/pkg/config" "github.com/owncloud/ocis-settings/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/server/grpc/option.go b/pkg/server/grpc/option.go index d5ab4e970..7f4f03815 100644 --- a/pkg/server/grpc/option.go +++ b/pkg/server/grpc/option.go @@ -4,9 +4,9 @@ import ( "context" "github.com/micro/cli/v2" - "github.com/owncloud/ocis-settings/pkg/metrics" - "github.com/owncloud/ocis-settings/pkg/config" "github.com/owncloud/ocis-pkg/v2/log" + "github.com/owncloud/ocis-settings/pkg/config" + "github.com/owncloud/ocis-settings/pkg/metrics" ) // Option defines a single option function. @@ -14,12 +14,12 @@ type Option func(o *Options) // Options defines the available options for this package. type Options struct { - Name string - Logger log.Logger - Context context.Context - Config *config.Config - Metrics *metrics.Metrics - Flags []cli.Flag + Name string + Logger log.Logger + Context context.Context + Config *config.Config + Metrics *metrics.Metrics + Flags []cli.Flag } // newOptions initializes the available default options. diff --git a/pkg/server/grpc/server.go b/pkg/server/grpc/server.go index 6b2f0946c..01388d9b5 100644 --- a/pkg/server/grpc/server.go +++ b/pkg/server/grpc/server.go @@ -1,9 +1,9 @@ package grpc import ( + "github.com/owncloud/ocis-pkg/v2/service/grpc" "github.com/owncloud/ocis-settings/pkg/proto/v0" svc "github.com/owncloud/ocis-settings/pkg/service/v0" - "github.com/owncloud/ocis-pkg/v2/service/grpc" "github.com/owncloud/ocis-settings/pkg/version" ) diff --git a/pkg/server/http/option.go b/pkg/server/http/option.go index 97e03b125..cb8ed8883 100644 --- a/pkg/server/http/option.go +++ b/pkg/server/http/option.go @@ -4,9 +4,9 @@ import ( "context" "github.com/micro/cli/v2" + "github.com/owncloud/ocis-pkg/v2/log" "github.com/owncloud/ocis-settings/pkg/config" "github.com/owncloud/ocis-settings/pkg/metrics" - "github.com/owncloud/ocis-pkg/v2/log" ) // Option defines a single option function. @@ -14,12 +14,12 @@ type Option func(o *Options) // Options defines the available options for this package. type Options struct { - Name string - Logger log.Logger - Context context.Context - Config *config.Config - Metrics *metrics.Metrics - Flags []cli.Flag + Name string + Logger log.Logger + Context context.Context + Config *config.Config + Metrics *metrics.Metrics + Flags []cli.Flag } // newOptions initializes the available default options. diff --git a/pkg/server/http/server.go b/pkg/server/http/server.go index 9c82d793a..ccad9beb8 100644 --- a/pkg/server/http/server.go +++ b/pkg/server/http/server.go @@ -67,6 +67,8 @@ func Server(opts ...Option) http.Service { mux, ) - service.Init() + if err := service.Init(); err != nil { + panic(err) + } return service } diff --git a/pkg/service/v0/instrument.go b/pkg/service/v0/instrument.go index 99025513c..ce0f5de1e 100644 --- a/pkg/service/v0/instrument.go +++ b/pkg/service/v0/instrument.go @@ -11,8 +11,3 @@ func NewInstrument(next Service, metrics *metrics.Metrics) Service { config: next.config, } } - -type instrument struct { - next Service - metrics *metrics.Metrics -} diff --git a/pkg/service/v0/logging.go b/pkg/service/v0/logging.go index c31d7bffc..ffcca4f3a 100644 --- a/pkg/service/v0/logging.go +++ b/pkg/service/v0/logging.go @@ -11,8 +11,3 @@ func NewLogging(next Service, logger log.Logger) Service { config: next.config, } } - -type logging struct { - next Service - logger log.Logger -} diff --git a/pkg/service/v0/option.go b/pkg/service/v0/option.go index 9bb036ed4..d0753227f 100644 --- a/pkg/service/v0/option.go +++ b/pkg/service/v0/option.go @@ -3,8 +3,8 @@ package svc import ( "net/http" - "github.com/owncloud/ocis-settings/pkg/config" "github.com/owncloud/ocis-pkg/v2/log" + "github.com/owncloud/ocis-settings/pkg/config" ) // Option defines a single option function. @@ -17,17 +17,6 @@ type Options struct { Middleware []func(http.Handler) http.Handler } -// newOptions initializes the available default options. -func newOptions(opts ...Option) Options { - opt := Options{} - - for _, o := range opts { - o(&opt) - } - - return opt -} - // Logger provides a function to set the logger option. func Logger(val log.Logger) Option { return func(o *Options) { diff --git a/pkg/service/v0/service.go b/pkg/service/v0/service.go index 4e7d3621f..574d251f8 100644 --- a/pkg/service/v0/service.go +++ b/pkg/service/v0/service.go @@ -2,6 +2,7 @@ package svc import ( "context" + "github.com/owncloud/ocis-settings/pkg/settings" store "github.com/owncloud/ocis-settings/pkg/store/filesystem" @@ -10,8 +11,8 @@ import ( ) type Service struct { - config *config.Config - manager settings.Manager + config *config.Config + manager settings.Manager } // NewService returns a service implementation for Service. diff --git a/pkg/service/v0/tracing.go b/pkg/service/v0/tracing.go index 0a39d51ac..e4a0e89da 100644 --- a/pkg/service/v0/tracing.go +++ b/pkg/service/v0/tracing.go @@ -7,7 +7,3 @@ func NewTracing(next Service) Service { config: next.config, } } - -type tracing struct { - next Service -} diff --git a/pkg/store/filesystem/bundles.go b/pkg/store/filesystem/bundles.go index fba9e04aa..b8ad11a7f 100644 --- a/pkg/store/filesystem/bundles.go +++ b/pkg/store/filesystem/bundles.go @@ -2,11 +2,12 @@ package store import ( + "io/ioutil" + "path" + "github.com/owncloud/ocis-settings/pkg/proto/v0" "google.golang.org/grpc/codes" gstatus "google.golang.org/grpc/status" - "io/ioutil" - "path" ) // ListBundles returns all bundles in the mountPath folder belonging to the given extension diff --git a/pkg/store/filesystem/io.go b/pkg/store/filesystem/io.go index d3a8c9d7c..6b76a16c5 100644 --- a/pkg/store/filesystem/io.go +++ b/pkg/store/filesystem/io.go @@ -1,9 +1,10 @@ package store import ( + "os" + "github.com/golang/protobuf/jsonpb" "github.com/golang/protobuf/proto" - "os" ) // Unmarshal file into record diff --git a/pkg/store/filesystem/paths.go b/pkg/store/filesystem/paths.go index 515708b24..5cc30d704 100644 --- a/pkg/store/filesystem/paths.go +++ b/pkg/store/filesystem/paths.go @@ -1,9 +1,10 @@ package store import ( - "github.com/owncloud/ocis-settings/pkg/proto/v0" "os" "path" + + "github.com/owncloud/ocis-settings/pkg/proto/v0" ) const folderNameBundles = "bundles" @@ -28,6 +29,13 @@ func (s Store) buildFilePathFromBundleArgs(extension string, bundleKey string) s return path.Join(extensionFolder, bundleKey+".json") } +// // Builds the folder path for storing settings values +// func (s Store) buildFolderPathValues() string { +// folderPath := path.Join(s.mountPath, folderNameValues) +// s.ensureFolderExists(folderPath) +// return folderPath +// } + // Builds a unique file name from the given settings value func (s Store) buildFilePathFromValue(value *proto.SettingsValue) string { return s.buildFilePathFromValueArgs(value.Identifier.AccountUuid, value.Identifier.Extension, value.Identifier.BundleKey) diff --git a/pkg/store/filesystem/values.go b/pkg/store/filesystem/values.go index 3204fe96a..1dc05e85b 100644 --- a/pkg/store/filesystem/values.go +++ b/pkg/store/filesystem/values.go @@ -2,12 +2,13 @@ package store import ( - "github.com/owncloud/ocis-settings/pkg/proto/v0" - "google.golang.org/grpc/codes" - gstatus "google.golang.org/grpc/status" "os" "path" "path/filepath" + + "github.com/owncloud/ocis-settings/pkg/proto/v0" + "google.golang.org/grpc/codes" + gstatus "google.golang.org/grpc/status" ) // ReadValue tries to find a value by the given identifier attributes within the mountPath