diff --git a/cmd/crowdsec-cli/decisions.go b/cmd/crowdsec-cli/decisions.go index dec9a7d01..8f3ba4a4d 100644 --- a/cmd/crowdsec-cli/decisions.go +++ b/cmd/crowdsec-cli/decisions.go @@ -29,8 +29,8 @@ var Client *apiclient.ApiClient func DecisionsToTable(alerts *models.GetAlertsResponse, printMachine bool) error { /*here we cheat a bit : to make it more readable for the user, we dedup some entries*/ - var spamLimit map[string]bool = make(map[string]bool) - var skipped = 0 + spamLimit := make(map[string]bool) + skipped := 0 for aIdx := 0; aIdx < len(*alerts); aIdx++ { alertItem := (*alerts)[aIdx] diff --git a/cmd/crowdsec/pour.go b/cmd/crowdsec/pour.go index ac323bfc9..adb072376 100644 --- a/cmd/crowdsec/pour.go +++ b/cmd/crowdsec/pour.go @@ -29,7 +29,7 @@ func runPour(input chan types.Event, holders []leaky.BucketFactory, buckets *lea //when in forensics mode, garbage collect buckets if cConfig.Crowdsec.BucketsGCEnabled { if parsed.MarshaledTime != "" { - var z *time.Time = &time.Time{} + z := &time.Time{} if err := z.UnmarshalText([]byte(parsed.MarshaledTime)); err != nil { log.Warningf("Failed to unmarshal time from event '%s' : %s", parsed.MarshaledTime, err) } else { diff --git a/pkg/acquisition/modules/file/file.go b/pkg/acquisition/modules/file/file.go index a98a0fd36..ad78c1e15 100644 --- a/pkg/acquisition/modules/file/file.go +++ b/pkg/acquisition/modules/file/file.go @@ -432,7 +432,7 @@ func (f *FileSource) tailFile(out chan types.Event, t *tomb.Tomb, tail *tail.Tai return err } return nil - case <-tail.Tomb.Dying(): //our tailer is dying + case <-tail.Dying(): //our tailer is dying logger.Warningf("File reader of %s died", tail.Filename) t.Kill(fmt.Errorf("dead reader for %s", tail.Filename)) return fmt.Errorf("reader for %s is dead", tail.Filename) diff --git a/pkg/alertcontext/alertcontext_test.go b/pkg/alertcontext/alertcontext_test.go index 8e6ca849a..2e7e71bd6 100644 --- a/pkg/alertcontext/alertcontext_test.go +++ b/pkg/alertcontext/alertcontext_test.go @@ -19,7 +19,7 @@ func TestNewAlertContext(t *testing.T) { { name: "basic config test", contextToSend: map[string][]string{ - "test": []string{"evt.Parsed.source_ip"}, + "test": {"evt.Parsed.source_ip"}, }, valueLength: 100, expectedErr: nil, @@ -45,8 +45,8 @@ func TestEventToContext(t *testing.T) { { name: "basic test", contextToSend: map[string][]string{ - "source_ip": []string{"evt.Parsed.source_ip"}, - "nonexistent_field": []string{"evt.Parsed.nonexist"}, + "source_ip": {"evt.Parsed.source_ip"}, + "nonexistent_field": {"evt.Parsed.nonexist"}, }, valueLength: 100, events: []types.Event{ @@ -67,9 +67,9 @@ func TestEventToContext(t *testing.T) { { name: "test many events", contextToSend: map[string][]string{ - "source_ip": []string{"evt.Parsed.source_ip"}, - "source_machine": []string{"evt.Parsed.source_machine"}, - "cve": []string{"evt.Parsed.cve"}, + "source_ip": {"evt.Parsed.source_ip"}, + "source_machine": {"evt.Parsed.source_machine"}, + "cve": {"evt.Parsed.cve"}, }, valueLength: 100, events: []types.Event{ @@ -113,9 +113,9 @@ func TestEventToContext(t *testing.T) { { name: "test many events with result above max length (need truncate, keep only 2 on 3 elements)", contextToSend: map[string][]string{ - "source_ip": []string{"evt.Parsed.source_ip"}, - "source_machine": []string{"evt.Parsed.source_machine"}, - "uri": []string{"evt.Parsed.uri"}, + "source_ip": {"evt.Parsed.source_ip"}, + "source_machine": {"evt.Parsed.source_machine"}, + "uri": {"evt.Parsed.uri"}, }, valueLength: 100, events: []types.Event{ @@ -159,9 +159,9 @@ func TestEventToContext(t *testing.T) { { name: "test one events with result above max length (need truncate on one element)", contextToSend: map[string][]string{ - "source_ip": []string{"evt.Parsed.source_ip"}, - "source_machine": []string{"evt.Parsed.source_machine"}, - "uri": []string{"evt.Parsed.uri"}, + "source_ip": {"evt.Parsed.source_ip"}, + "source_machine": {"evt.Parsed.source_machine"}, + "uri": {"evt.Parsed.uri"}, }, valueLength: 100, events: []types.Event{ diff --git a/pkg/apiclient/alerts_service_test.go b/pkg/apiclient/alerts_service_test.go index 8043536e5..4270851d5 100644 --- a/pkg/apiclient/alerts_service_test.go +++ b/pkg/apiclient/alerts_service_test.go @@ -124,7 +124,7 @@ func TestAlertsListAsMachine(t *testing.T) { Capacity: &tcapacity, CreatedAt: "2020-11-28T10:20:47+01:00", Decisions: []*models.Decision{ - &models.Decision{ + { Duration: &tduration, ID: 1, Origin: &torigin, @@ -137,7 +137,7 @@ func TestAlertsListAsMachine(t *testing.T) { }, }, Events: []*models.Event{ - &models.Event{ + { Meta: models.Meta{ &models.MetaItems0{ Key: "target_user", @@ -149,8 +149,7 @@ func TestAlertsListAsMachine(t *testing.T) { }, }, Timestamp: &ttimestamp, - }, - &models.Event{ + }, { Meta: models.Meta{ &models.MetaItems0{ Key: "target_user", @@ -323,7 +322,7 @@ func TestAlertsGetAsMachine(t *testing.T) { Capacity: &tcapacity, CreatedAt: "2020-11-28T10:20:47+01:00", Decisions: []*models.Decision{ - &models.Decision{ + { Duration: &tduration, ID: 1, Origin: &torigin, @@ -336,7 +335,7 @@ func TestAlertsGetAsMachine(t *testing.T) { }, }, Events: []*models.Event{ - &models.Event{ + { Meta: models.Meta{ &models.MetaItems0{ Key: "target_user", @@ -348,8 +347,7 @@ func TestAlertsGetAsMachine(t *testing.T) { }, }, Timestamp: &ttimestamp, - }, - &models.Event{ + }, { Meta: models.Meta{ &models.MetaItems0{ Key: "target_user", diff --git a/pkg/csplugin/watcher.go b/pkg/csplugin/watcher.go index a95ade5f7..983a53c89 100644 --- a/pkg/csplugin/watcher.go +++ b/pkg/csplugin/watcher.go @@ -82,7 +82,7 @@ func (pw *PluginWatcher) Start(tomb *tomb.Tomb) { func (pw *PluginWatcher) watchPluginTicker(pluginName string) { var watchTime time.Duration - var watchCount int = -1 + watchCount := -1 // Threshold can be set : by time, by count, or both // if only time is set, honor it // if only count is set, put timer to 1 second and just check size @@ -108,7 +108,7 @@ func (pw *PluginWatcher) watchPluginTicker(pluginName string) { } ticker := time.NewTicker(watchTime) - var lastSend time.Time = time.Now() + lastSend := time.Now() for { select { case <-ticker.C: diff --git a/pkg/cticlient/types.go b/pkg/cticlient/types.go index c26da39fb..1d6550d00 100644 --- a/pkg/cticlient/types.go +++ b/pkg/cticlient/types.go @@ -147,7 +147,7 @@ type FireResponse struct { } func (c *SmokeItem) GetAttackDetails() []string { - var ret []string = make([]string, 0) + ret := make([]string, 0) if c.AttackDetails != nil { for _, b := range c.AttackDetails { @@ -158,7 +158,7 @@ func (c *SmokeItem) GetAttackDetails() []string { } func (c *SmokeItem) GetBehaviors() []string { - var ret []string = make([]string, 0) + ret := make([]string, 0) if c.Behaviors != nil { for _, b := range c.Behaviors { @@ -199,7 +199,7 @@ func (c *SmokeItem) GetBackgroundNoiseScore() int { } func (c *SmokeItem) GetFalsePositives() []string { - var ret []string = make([]string, 0) + ret := make([]string, 0) if c.Classifications.FalsePositives != nil { for _, b := range c.Classifications.FalsePositives { @@ -221,7 +221,7 @@ func (c *SmokeItem) IsFalsePositive() bool { } func (c *FireItem) GetAttackDetails() []string { - var ret []string = make([]string, 0) + ret := make([]string, 0) if c.AttackDetails != nil { for _, b := range c.AttackDetails { @@ -232,7 +232,7 @@ func (c *FireItem) GetAttackDetails() []string { } func (c *FireItem) GetBehaviors() []string { - var ret []string = make([]string, 0) + ret := make([]string, 0) if c.Behaviors != nil { for _, b := range c.Behaviors { @@ -273,7 +273,7 @@ func (c *FireItem) GetBackgroundNoiseScore() int { } func (c *FireItem) GetFalsePositives() []string { - var ret []string = make([]string, 0) + ret := make([]string, 0) if c.Classifications.FalsePositives != nil { for _, b := range c.Classifications.FalsePositives { diff --git a/pkg/database/decisions.go b/pkg/database/decisions.go index 7ad1a1206..61483f9fd 100644 --- a/pkg/database/decisions.go +++ b/pkg/database/decisions.go @@ -27,7 +27,7 @@ func BuildDecisionRequestWithFilter(query *ent.DecisionQuery, filter map[string] var err error var start_ip, start_sfx, end_ip, end_sfx int64 var ip_sz int - var contains bool = true + var contains = true /*if contains is true, return bans that *contains* the given value (value is the inner) else, return bans that are *contained* by the given value (value is the outer)*/ @@ -311,7 +311,7 @@ func (c *Client) DeleteDecisionsWithFilter(filter map[string][]string) (string, var err error var start_ip, start_sfx, end_ip, end_sfx int64 var ip_sz int - var contains bool = true + var contains = true /*if contains is true, return bans that *contains* the given value (value is the inner) else, return bans that are *contained* by the given value (value is the outer) */ @@ -427,7 +427,7 @@ func (c *Client) SoftDeleteDecisionsWithFilter(filter map[string][]string) (stri var err error var start_ip, start_sfx, end_ip, end_sfx int64 var ip_sz int - var contains bool = true + var contains = true /*if contains is true, return bans that *contains* the given value (value is the inner) else, return bans that are *contained* by the given value (value is the outer)*/ decisions := c.Ent.Decision.Query().Where(decision.UntilGT(time.Now().UTC())) diff --git a/pkg/exprhelpers/crowdsec_cti_test.go b/pkg/exprhelpers/crowdsec_cti_test.go index 90beee0f8..7e9bc0c31 100644 --- a/pkg/exprhelpers/crowdsec_cti_test.go +++ b/pkg/exprhelpers/crowdsec_cti_test.go @@ -53,7 +53,7 @@ var sampledata = map[string]cticlient.SmokeItem{ }, }, //1.2.3.7 is a ok guy, but part of a bad range - "1.2.3.7": cticlient.SmokeItem{}, + "1.2.3.7": {}, } const validApiKey = "my-api-key" diff --git a/pkg/leakybucket/blackhole.go b/pkg/leakybucket/blackhole.go index dd46d11ae..3a2740c46 100644 --- a/pkg/leakybucket/blackhole.go +++ b/pkg/leakybucket/blackhole.go @@ -33,7 +33,7 @@ func NewBlackhole(bucketFactory *BucketFactory) (*Blackhole, error) { func (bl *Blackhole) OnBucketOverflow(bucketFactory *BucketFactory) func(*Leaky, types.RuntimeAlert, *Queue) (types.RuntimeAlert, *Queue) { return func(leaky *Leaky, alert types.RuntimeAlert, queue *Queue) (types.RuntimeAlert, *Queue) { - var blackholed bool = false + var blackholed = false var tmp []HiddenKey // search if we are blackholed and refresh the slice for _, element := range bl.hiddenKeys { diff --git a/pkg/leakybucket/bucket.go b/pkg/leakybucket/bucket.go index b2f97169d..35d91833c 100644 --- a/pkg/leakybucket/bucket.go +++ b/pkg/leakybucket/bucket.go @@ -201,9 +201,9 @@ func FromFactory(bucketFactory BucketFactory) *Leaky { func LeakRoutine(leaky *Leaky) error { var ( - durationTickerChan <-chan time.Time = make(<-chan time.Time) + durationTickerChan = make(<-chan time.Time) durationTicker *time.Ticker - firstEvent bool = true + firstEvent = true ) defer types.CatchPanic(fmt.Sprintf("crowdsec/LeakRoutine/%s", leaky.Name)) diff --git a/pkg/leakybucket/buckets_test.go b/pkg/leakybucket/buckets_test.go index 833a4aa37..d50016bc2 100644 --- a/pkg/leakybucket/buckets_test.go +++ b/pkg/leakybucket/buckets_test.go @@ -30,8 +30,8 @@ type TestFile struct { func TestBucket(t *testing.T) { var ( - envSetting = os.Getenv("TEST_ONLY") - tomb *tomb.Tomb = &tomb.Tomb{} + envSetting = os.Getenv("TEST_ONLY") + tomb = &tomb.Tomb{} ) err := exprhelpers.Init(nil) if err != nil { diff --git a/pkg/leakybucket/manager_load.go b/pkg/leakybucket/manager_load.go index dfcdcee4f..9644ccd76 100644 --- a/pkg/leakybucket/manager_load.go +++ b/pkg/leakybucket/manager_load.go @@ -158,7 +158,7 @@ func ValidateFactory(bucketFactory *BucketFactory) error { func LoadBuckets(cscfg *csconfig.CrowdsecServiceCfg, files []string, tomb *tomb.Tomb, buckets *Buckets) ([]BucketFactory, chan types.Event, error) { var ( - ret []BucketFactory = []BucketFactory{} + ret = []BucketFactory{} response chan types.Event ) diff --git a/pkg/leakybucket/manager_load_test.go b/pkg/leakybucket/manager_load_test.go index 8ba56978a..bb3df75cd 100644 --- a/pkg/leakybucket/manager_load_test.go +++ b/pkg/leakybucket/manager_load_test.go @@ -14,7 +14,7 @@ type cfgTest struct { } func runTest(tests []cfgTest) error { - var tomb *tomb.Tomb = &tomb.Tomb{} + var tomb = &tomb.Tomb{} for idx, cfg := range tests { err := LoadBucket(&cfg.cfg, tomb) if cfg.loadable && err != nil { diff --git a/pkg/leakybucket/manager_run_test.go b/pkg/leakybucket/manager_run_test.go index f654a2781..27b665f75 100644 --- a/pkg/leakybucket/manager_run_test.go +++ b/pkg/leakybucket/manager_run_test.go @@ -25,13 +25,13 @@ func expectBucketCount(buckets *Buckets, expected int) error { func TestGCandDump(t *testing.T) { var ( - buckets *Buckets = NewBuckets() - tomb *tomb.Tomb = &tomb.Tomb{} + buckets = NewBuckets() + tomb = &tomb.Tomb{} ) var Holders = []BucketFactory{ //one overflowing soon + bh - BucketFactory{ + { Name: "test_counter_fast", Description: "test_counter_fast", Debug: true, @@ -44,7 +44,7 @@ func TestGCandDump(t *testing.T) { wgPour: buckets.wgPour, }, //one long counter - BucketFactory{ + { Name: "test_counter_slow", Description: "test_counter_slow", Debug: true, @@ -56,7 +56,7 @@ func TestGCandDump(t *testing.T) { wgPour: buckets.wgPour, }, //slow leaky - BucketFactory{ + { Name: "test_leaky_slow", Description: "test_leaky_slow", Debug: true, @@ -115,10 +115,10 @@ func TestGCandDump(t *testing.T) { func TestShutdownBuckets(t *testing.T) { var ( - buckets *Buckets = NewBuckets() - Holders = []BucketFactory{ + buckets = NewBuckets() + Holders = []BucketFactory{ //one long counter - BucketFactory{ + { Name: "test_counter_slow", Description: "test_counter_slow", Debug: true, @@ -130,7 +130,7 @@ func TestShutdownBuckets(t *testing.T) { wgPour: buckets.wgPour, }, //slow leaky - BucketFactory{ + { Name: "test_leaky_slow", Description: "test_leaky_slow", Debug: true, @@ -142,7 +142,7 @@ func TestShutdownBuckets(t *testing.T) { wgPour: buckets.wgPour, }, } - tomb *tomb.Tomb = &tomb.Tomb{} + tomb = &tomb.Tomb{} ) for idx := range Holders { diff --git a/pkg/leakybucket/overflows.go b/pkg/leakybucket/overflows.go index 3c1f3ebc5..c1f051523 100644 --- a/pkg/leakybucket/overflows.go +++ b/pkg/leakybucket/overflows.go @@ -210,7 +210,7 @@ func EventsFromQueue(queue *Queue) []*models.Event { // alertFormatSource iterates over the queue to collect sources func alertFormatSource(leaky *Leaky, queue *Queue) (map[string]models.Source, string, error) { - var sources map[string]models.Source = make(map[string]models.Source) + var sources = make(map[string]models.Source) var source_type string log.Debugf("Formatting (%s) - scope Info : scope_type:%s / scope_filter:%s", leaky.Name, leaky.scopeType.Scope, leaky.scopeType.Filter) diff --git a/pkg/metabase/container.go b/pkg/metabase/container.go index b53803b1a..e73660695 100644 --- a/pkg/metabase/container.go +++ b/pkg/metabase/container.go @@ -139,7 +139,7 @@ func StopContainer(name string) error { return fmt.Errorf("failed to create docker client : %s", err) } ctx := context.Background() - var to time.Duration = 20 * time.Second + to := 20 * time.Second if err := cli.ContainerStop(ctx, name, &to); err != nil { return fmt.Errorf("failed while stopping %s : %s", name, err) } diff --git a/pkg/parser/enrich_date.go b/pkg/parser/enrich_date.go index 0d07bc0d6..b7d615afc 100644 --- a/pkg/parser/enrich_date.go +++ b/pkg/parser/enrich_date.go @@ -57,7 +57,7 @@ func GenDateParse(date string) (string, time.Time) { func ParseDate(in string, p *types.Event, x interface{}, plog *log.Entry) (map[string]string, error) { - var ret map[string]string = make(map[string]string) + var ret = make(map[string]string) var strDate string var parsedDate time.Time if in != "" { diff --git a/pkg/parser/parsing_test.go b/pkg/parser/parsing_test.go index cde09ee5b..34d36f07d 100644 --- a/pkg/parser/parsing_test.go +++ b/pkg/parser/parsing_test.go @@ -196,7 +196,7 @@ func loadTestFile(file string) []TestFile { func matchEvent(expected types.Event, out types.Event, debug bool) ([]string, bool) { var retInfo []string - var valid bool = false + var valid = false expectMaps := []map[string]string{expected.Parsed, expected.Meta, expected.Enriched} outMaps := []map[string]string{out.Parsed, out.Meta, out.Enriched} outLabels := []string{"Parsed", "Meta", "Enriched"} diff --git a/pkg/parser/runtime.go b/pkg/parser/runtime.go index 84c58282b..a077af13f 100644 --- a/pkg/parser/runtime.go +++ b/pkg/parser/runtime.go @@ -245,7 +245,7 @@ var DumpFolder string var StageParseCache map[string]map[string][]ParserResult func Parse(ctx UnixParserCtx, xp types.Event, nodes []Node) (types.Event, error) { - var event types.Event = xp + var event = xp /* the stage is undefined, probably line is freshly acquired, set to first stage !*/ if event.Stage == "" && len(ctx.Stages) > 0 {