diff --git a/.golangci.yml b/.golangci.yml index b51f17df489..be99c1fd174 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -200,6 +200,29 @@ linters-settings: - docStub - preferFprint + unused: + # Mark all struct fields that have been written to as used. + # Default: true + field-writes-are-uses: false + # Treat IncDec statement (e.g. `i++` or `i--`) as both read and write operation instead of just write. + # Default: false + post-statements-are-reads: true + # Mark all exported identifiers as used. + # Default: true + # exported-is-used: false + # Mark all exported fields as used. + # default: true + exported-fields-are-used: false + # Mark all function parameters as used. + # default: true + parameters-are-used: true + # Mark all local variables as used. + # default: true + local-variables-are-used: false + # Mark all identifiers inside generated files as used. + # Default: true + generated-is-used: false + linters: enable-all: true disable: diff --git a/pkg/acquisition/acquisition_test.go b/pkg/acquisition/acquisition_test.go index cfe1e74c612..6509c2e41ca 100644 --- a/pkg/acquisition/acquisition_test.go +++ b/pkg/acquisition/acquisition_test.go @@ -305,11 +305,9 @@ func TestLoadAcquisitionFromFile(t *testing.T) { type MockCat struct { configuration.DataSourceCommonCfg `yaml:",inline"` - logger *log.Entry } func (f *MockCat) Configure(cfg []byte, logger *log.Entry, metricsLevel int) error { - f.logger = logger if f.Mode == "" { f.Mode = configuration.CAT_MODE } @@ -350,11 +348,9 @@ func (f *MockCat) GetUuid() string { return "" } type MockTail struct { configuration.DataSourceCommonCfg `yaml:",inline"` - logger *log.Entry } func (f *MockTail) Configure(cfg []byte, logger *log.Entry, metricsLevel int) error { - f.logger = logger if f.Mode == "" { f.Mode = configuration.TAIL_MODE } diff --git a/pkg/acquisition/modules/appsec/appsec.go b/pkg/acquisition/modules/appsec/appsec.go index 2f7861b32ff..0c84889d26d 100644 --- a/pkg/acquisition/modules/appsec/appsec.go +++ b/pkg/acquisition/modules/appsec/appsec.go @@ -49,12 +49,10 @@ type AppsecSourceConfig struct { // runtime structure of AppsecSourceConfig type AppsecSource struct { - metricsLevel int config AppsecSourceConfig logger *log.Entry mux *http.ServeMux server *http.Server - outChan chan types.Event InChan chan appsec.ParsedRequest AppsecRuntime *appsec.AppsecRuntimeConfig AppsecConfigs map[string]appsec.AppsecConfig @@ -162,7 +160,6 @@ func (w *AppsecSource) Configure(yamlConfig []byte, logger *log.Entry, MetricsLe } w.logger = logger - w.metricsLevel = MetricsLevel w.logger.Tracef("Appsec configuration: %+v", w.config) if w.config.AuthCacheDuration == nil { @@ -266,8 +263,6 @@ func (w *AppsecSource) OneShotAcquisition(_ context.Context, _ chan types.Event, } func (w *AppsecSource) StreamingAcquisition(ctx context.Context, out chan types.Event, t *tomb.Tomb) error { - w.outChan = out - t.Go(func() error { defer trace.CatchPanic("crowdsec/acquis/appsec/live") diff --git a/pkg/apiserver/apic.go b/pkg/apiserver/apic.go index 32847f7489a..ad59faea8d8 100644 --- a/pkg/apiserver/apic.go +++ b/pkg/apiserver/apic.go @@ -64,7 +64,6 @@ type apic struct { pullTomb tomb.Tomb metricsTomb tomb.Tomb startup bool - credentials *csconfig.ApiCredentialsCfg scenarioList []string consoleConfig *csconfig.ConsoleConfig isPulling chan bool @@ -186,7 +185,6 @@ func NewAPIC(ctx context.Context, config *csconfig.OnlineApiClientCfg, dbClient dbClient: dbClient, mu: sync.Mutex{}, startup: true, - credentials: config.Credentials, pullTomb: tomb.Tomb{}, pushTomb: tomb.Tomb{}, metricsTomb: tomb.Tomb{}, diff --git a/pkg/apiserver/apiserver.go b/pkg/apiserver/apiserver.go index e1d9ce95349..1992b0c7c2d 100644 --- a/pkg/apiserver/apiserver.go +++ b/pkg/apiserver/apiserver.go @@ -35,7 +35,6 @@ type APIServer struct { UnixSocket string TLS *csconfig.TLSCfg dbClient *database.Client - logFile string controller *controllers.Controller flushScheduler *gocron.Scheduler router *gin.Engine @@ -200,7 +199,7 @@ func NewServer(ctx context.Context, config *csconfig.LocalApiServerCfg) (*APISer } // The logger that will be used by handlers - clog, logFile, err := newGinLogger(config) + clog, _, err := newGinLogger(config) if err != nil { return nil, err } @@ -284,7 +283,6 @@ func NewServer(ctx context.Context, config *csconfig.LocalApiServerCfg) (*APISer URL: config.ListenURI, UnixSocket: config.ListenSocket, TLS: config.TLS, - logFile: logFile, dbClient: dbClient, controller: controller, flushScheduler: flushScheduler, diff --git a/pkg/csplugin/broker.go b/pkg/csplugin/broker.go index f53c831e186..4441ca2cb84 100644 --- a/pkg/csplugin/broker.go +++ b/pkg/csplugin/broker.go @@ -44,7 +44,6 @@ type PluginBroker struct { profileConfigs []*csconfig.ProfileCfg pluginConfigByName map[string]PluginConfig pluginMap map[string]plugin.Plugin - notificationConfigsByPluginType map[string][][]byte // "slack" -> []{config1, config2} notificationPluginByName map[string]protobufs.NotifierServer watcher PluginWatcher pluginKillMethods []func() @@ -74,7 +73,6 @@ type ProfileAlert struct { func (pb *PluginBroker) Init(ctx context.Context, pluginCfg *csconfig.PluginCfg, profileConfigs []*csconfig.ProfileCfg, configPaths *csconfig.ConfigurationPaths) error { pb.PluginChannel = make(chan ProfileAlert) - pb.notificationConfigsByPluginType = make(map[string][][]byte) pb.notificationPluginByName = make(map[string]protobufs.NotifierServer) pb.pluginMap = make(map[string]plugin.Plugin) pb.pluginConfigByName = make(map[string]PluginConfig) diff --git a/pkg/leakybucket/manager_load.go b/pkg/leakybucket/manager_load.go index 5e8bab8486e..fdbb4d7e61d 100644 --- a/pkg/leakybucket/manager_load.go +++ b/pkg/leakybucket/manager_load.go @@ -65,7 +65,6 @@ type BucketFactory struct { duration time.Duration // internal representation of `Duration` ret chan types.Event // the bucket-specific output chan for overflows processors []Processor // processors is the list of hooks for pour/overflow/create (cf. uniq, blackhole etc.) - output bool // ?? ScenarioVersion string `yaml:"version,omitempty"` hash string Simulated bool `yaml:"simulated"` // Set to true if the scenario instantiating the bucket was in the exclusion list @@ -462,7 +461,6 @@ func LoadBucket(bucketFactory *BucketFactory, tomb *tomb.Tomb) error { } } - bucketFactory.output = false if err := ValidateFactory(bucketFactory); err != nil { return fmt.Errorf("invalid bucket from %s: %w", bucketFactory.Filename, err) } diff --git a/pkg/leakybucket/manager_run.go b/pkg/leakybucket/manager_run.go index e6712e6e47e..8127483d9b9 100644 --- a/pkg/leakybucket/manager_run.go +++ b/pkg/leakybucket/manager_run.go @@ -33,16 +33,12 @@ func GarbageCollectBuckets(deadline time.Time, buckets *Buckets) error { buckets.wgDumpState.Add(1) defer buckets.wgDumpState.Done() - total := 0 - discard := 0 toflush := []string{} buckets.Bucket_map.Range(func(rkey, rvalue interface{}) bool { key := rkey.(string) val := rvalue.(*Leaky) - total += 1 //bucket already overflowed, we can kill it if !val.Ovflw_ts.IsZero() { - discard += 1 val.logger.Debugf("overflowed at %s.", val.Ovflw_ts) toflush = append(toflush, key) val.tomb.Kill(nil) @@ -97,12 +93,10 @@ func DumpBucketsStateAt(deadline time.Time, outputdir string, buckets *Buckets) tmpFileName := tmpFd.Name() serialized = make(map[string]Leaky) log.Printf("Dumping buckets state at %s", deadline) - total := 0 discard := 0 buckets.Bucket_map.Range(func(rkey, rvalue interface{}) bool { key := rkey.(string) val := rvalue.(*Leaky) - total += 1 if !val.Ovflw_ts.IsZero() { discard += 1 val.logger.Debugf("overflowed at %s.", val.Ovflw_ts)