Skip to content

Commit

Permalink
lint: gocritic (nestingReduce)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Sep 2, 2024
1 parent 9780841 commit f7826fa
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 50 deletions.
27 changes: 14 additions & 13 deletions cmd/crowdsec-cli/cliconsole/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,24 @@ func (cli *cliConsole) enroll(key string, name string, overwrite bool, tags []st
}

for _, availableOpt := range csconfig.CONSOLE_CONFIGS {
if opt == availableOpt {
valid = true
enable := true

for _, enabledOpt := range enableOpts {
if opt == enabledOpt {
enable = false
continue
}
}
if opt != availableOpt {
continue
}
valid = true
enable := true

if enable {
enableOpts = append(enableOpts, opt)
for _, enabledOpt := range enableOpts {
if opt == enabledOpt {
enable = false
continue
}
}

break
if enable {
enableOpts = append(enableOpts, opt)
}

break
}

if !valid {
Expand Down
15 changes: 8 additions & 7 deletions pkg/exprhelpers/debugger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,15 @@ func TestBaseDbg(t *testing.T) {

}
for i, out := range outdbg {
if !reflect.DeepEqual(out, test.ExpectedOutputs[i]) {
spew.Config.DisableMethods = true
t.Errorf("failed test %s", test.Name)
t.Errorf("expected : %#v", test.ExpectedOutputs[i])
t.Errorf("got : %#v", out)
t.Fatalf("%d/%d : mismatch", i, len(outdbg))
if reflect.DeepEqual(out, test.ExpectedOutputs[i]) {
//DisplayExprDebug(prog, outdbg, logger, ret)
continue
}
//DisplayExprDebug(prog, outdbg, logger, ret)
spew.Config.DisableMethods = true
t.Errorf("failed test %s", test.Name)
t.Errorf("expected : %#v", test.ExpectedOutputs[i])
t.Errorf("got : %#v", out)
t.Fatalf("%d/%d : mismatch", i, len(outdbg))
}
}
}
61 changes: 31 additions & 30 deletions pkg/leakybucket/manager_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,37 +509,38 @@ func LoadBucketsState(file string, buckets *Buckets, bucketFactories []BucketFac
found := false

for _, h := range bucketFactories {
if h.Name == v.Name {
log.Debugf("found factory %s/%s -> %s", h.Author, h.Name, h.Description)
// check in which mode the bucket was
if v.Mode == types.TIMEMACHINE {
tbucket = NewTimeMachine(h)
} else if v.Mode == types.LIVE {
tbucket = NewLeaky(h)
} else {
log.Errorf("Unknown bucket type : %d", v.Mode)
}
/*Trying to restore queue state*/
tbucket.Queue = v.Queue
/*Trying to set the limiter to the saved values*/
tbucket.Limiter.Load(v.SerializedState)
tbucket.In = make(chan *types.Event)
tbucket.Mapkey = k
tbucket.Signal = make(chan bool, 1)
tbucket.First_ts = v.First_ts
tbucket.Last_ts = v.Last_ts
tbucket.Ovflw_ts = v.Ovflw_ts
tbucket.Total_count = v.Total_count
buckets.Bucket_map.Store(k, tbucket)
h.tomb.Go(func() error {
return LeakRoutine(tbucket)
})
<-tbucket.Signal

found = true

break
if h.Name != v.Name {
continue
}
log.Debugf("found factory %s/%s -> %s", h.Author, h.Name, h.Description)
// check in which mode the bucket was
if v.Mode == types.TIMEMACHINE {
tbucket = NewTimeMachine(h)
} else if v.Mode == types.LIVE {
tbucket = NewLeaky(h)
} else {
log.Errorf("Unknown bucket type : %d", v.Mode)
}
/*Trying to restore queue state*/
tbucket.Queue = v.Queue
/*Trying to set the limiter to the saved values*/
tbucket.Limiter.Load(v.SerializedState)
tbucket.In = make(chan *types.Event)
tbucket.Mapkey = k
tbucket.Signal = make(chan bool, 1)
tbucket.First_ts = v.First_ts
tbucket.Last_ts = v.Last_ts
tbucket.Ovflw_ts = v.Ovflw_ts
tbucket.Total_count = v.Total_count
buckets.Bucket_map.Store(k, tbucket)
h.tomb.Go(func() error {
return LeakRoutine(tbucket)
})
<-tbucket.Signal

found = true

break
}

if !found {
Expand Down

0 comments on commit f7826fa

Please sign in to comment.