Skip to content
Closed
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
12 changes: 7 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ linters:
- cyclop
- errname
- exhaustive
- exportloopref
- copyloopvar
- gocritic
- gofmt
- gosimple
Expand All @@ -16,15 +16,17 @@ linters:
- stylecheck
- typecheck
- unused
run:
go: "1.22"
linters-settings:
stylecheck:
go: "1.22"
gocritic:
enabled-checks:
- hugeParam
- rangeExprCopy
- rangeValCopy
- indexAlloc
- deprecatedComment
settings:
ifElseChain:
minThreshold: 3
cyclop:
max-complexity: 150 # TODO: reduce that to 20
max-complexity: 150 # TODO: reduce that to 20
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ifneq ($(CLEAN_BUILD),)
LDFLAGS ?= -X 'main.buildVersion=${VERSION}-${BUILD_SHA}' -X 'main.buildDate=${BUILD_DATE}'
endif

GOLANGCI_LINT_VERSION = v1.54.2
GOLANGCI_LINT_VERSION = v1.61.0
YQ_VERSION = v4.43.1

# build a single arch target provided as argument
Expand Down
56 changes: 56 additions & 0 deletions cmd/display_loop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cmd

import "slices"

type displayLoop struct {
all []displayLoopItem
current int
}

type displayLoopItem struct {
name string
columns []string
group []string
}

func (dl *displayLoop) prev() {
dl.current += len(dl.all) - 1
dl.current %= len(dl.all)
}

func (dl *displayLoop) next() {
dl.current++
dl.current %= len(dl.all)
}

func (dl *displayLoop) getCurrentItems() []displayLoopItem {
current := dl.all[dl.current]
if current.group == nil {
return []displayLoopItem{current}
}
var items []displayLoopItem
for _, item := range dl.all {
if slices.Contains(current.group, item.name) {
items = append(items, item)
}
}
return items
}

func (dl *displayLoop) getNames() []string {
var names []string
items := dl.getCurrentItems()
for _, item := range items {
names = append(names, item.name)
}
return names
}

func (dl *displayLoop) getCols() []string {
var cols []string
items := dl.getCurrentItems()
for _, item := range items {
cols = append(cols, item.columns...)
}
return cols
}
38 changes: 38 additions & 0 deletions cmd/display_loop_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cmd

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestDisplayLoop(t *testing.T) {
enrichment.current = 0
assert.Equal(t, []string{"None"}, enrichment.getNames())
assert.Equal(t, []string{"SrcAddr", "SrcPort", "DstAddr", "DstPort"}, enrichment.getCols())

enrichment.prev()
assert.Equal(t, []string{"Zone", "Host", "Owner", "Resource"}, enrichment.getNames())
assert.Equal(t, []string{
"SrcZone",
"DstZone",
"SrcHostName",
"SrcHostName",
"SrcOwnerName",
"SrcOwnerType",
"DstOwnerName",
"DstOwnerType",
"SrcName",
"SrcType",
"DstName",
"DstType",
}, enrichment.getCols())

enrichment.next()
assert.Equal(t, []string{"None"}, enrichment.getNames())
assert.Equal(t, []string{"SrcAddr", "SrcPort", "DstAddr", "DstPort"}, enrichment.getCols())

enrichment.next()
assert.Equal(t, []string{"Zone"}, enrichment.getNames())
assert.Equal(t, []string{"SrcZone", "DstZone"}, enrichment.getCols())
}
Loading
Loading