Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact: remove unused struct fields, enable related linter #3334

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 0 additions & 4 deletions pkg/acquisition/acquisition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/acquisition/modules/appsec/appsec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")

Expand Down
2 changes: 0 additions & 2 deletions pkg/apiserver/apic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{},
Expand Down
4 changes: 1 addition & 3 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions pkg/csplugin/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@
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()
pluginProcConfig *csconfig.PluginCfg

Check failure on line 50 in pkg/csplugin/broker.go

View workflow job for this annotation

GitHub Actions / Build + tests

field `pluginProcConfig` is unused (unused)
pluginsTypesToDispatch map[string]struct{}
}

Expand All @@ -74,7 +73,6 @@

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)
Expand Down
2 changes: 0 additions & 2 deletions pkg/leakybucket/manager_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/leakybucket/manager_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading