Lint (type inference): remove redundant type declarations (#2111)
This commit is contained in:
parent
9faa49c7e8
commit
e161507d08
20 changed files with 56 additions and 58 deletions
|
@ -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]
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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{
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()))
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -31,7 +31,7 @@ type TestFile struct {
|
|||
func TestBucket(t *testing.T) {
|
||||
var (
|
||||
envSetting = os.Getenv("TEST_ONLY")
|
||||
tomb *tomb.Tomb = &tomb.Tomb{}
|
||||
tomb = &tomb.Tomb{}
|
||||
)
|
||||
err := exprhelpers.Init(nil)
|
||||
if err != nil {
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 != "" {
|
||||
|
|
|
@ -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"}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue