Fix staticcheck issues (#266)

This commit is contained in:
turekt 2024-08-11 10:00:48 +02:00 committed by GitHub
parent b76fdc8f90
commit 4d451ef75f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 28 additions and 30 deletions

View File

@ -219,7 +219,7 @@ func (cc *Conn) getFlowtables(t *Table) ([]netlink.Message, error) {
reply, err := receiveAckAware(conn, message.Header.Flags) reply, err := receiveAckAware(conn, message.Header.Flags)
if err != nil { if err != nil {
return nil, fmt.Errorf("Receive: %v", err) return nil, fmt.Errorf("receiveAckAware: %v", err)
} }
return reply, nil return reply, nil

View File

@ -62,29 +62,27 @@ func TestMonitor(t *testing.T) {
defer wg.Done() defer wg.Done()
count := int32(0) count := int32(0)
for { for {
select { event, ok := <-events
case event, ok := <-events: if !ok {
if !ok { return
return }
} if event.Error != nil {
if event.Error != nil { err = fmt.Errorf("monitor err: %s", event.Error)
err = fmt.Errorf("monitor err: %s", event.Error) return
return }
} switch event.Type {
switch event.Type { case nftables.MonitorEventTypeNewTable:
case nftables.MonitorEventTypeNewTable: gotTable = event.Data.(*nftables.Table)
gotTable = event.Data.(*nftables.Table) atomic.AddInt32(&count, 1)
atomic.AddInt32(&count, 1) case nftables.MonitorEventTypeNewChain:
case nftables.MonitorEventTypeNewChain: gotChain = event.Data.(*nftables.Chain)
gotChain = event.Data.(*nftables.Chain) atomic.AddInt32(&count, 1)
atomic.AddInt32(&count, 1) case nftables.MonitorEventTypeNewRule:
case nftables.MonitorEventTypeNewRule: gotRule = event.Data.(*nftables.Rule)
gotRule = event.Data.(*nftables.Rule) atomic.AddInt32(&count, 1)
atomic.AddInt32(&count, 1) }
} if atomic.LoadInt32(&count) == 3 {
if atomic.LoadInt32(&count) == 3 { return
return
}
} }
} }
}() }()

2
obj.go
View File

@ -354,7 +354,7 @@ func (cc *Conn) getObjWithLegacyType(o Obj, t *Table, msgType uint16, returnLega
reply, err := receiveAckAware(conn, message.Header.Flags) reply, err := receiveAckAware(conn, message.Header.Flags)
if err != nil { if err != nil {
return nil, fmt.Errorf("Receive: %v", err) return nil, fmt.Errorf("receiveAckAware: %v", err)
} }
var objs []Obj var objs []Obj
for _, msg := range reply { for _, msg := range reply {

View File

@ -92,7 +92,7 @@ func (cc *Conn) GetRules(t *Table, c *Chain) ([]*Rule, error) {
reply, err := receiveAckAware(conn, message.Header.Flags) reply, err := receiveAckAware(conn, message.Header.Flags)
if err != nil { if err != nil {
return nil, fmt.Errorf("Receive: %v", err) return nil, fmt.Errorf("receiveAckAware: %v", err)
} }
var rules []*Rule var rules []*Rule
for _, msg := range reply { for _, msg := range reply {

8
set.go
View File

@ -832,7 +832,7 @@ func (cc *Conn) GetSets(t *Table) ([]*Set, error) {
reply, err := receiveAckAware(conn, message.Header.Flags) reply, err := receiveAckAware(conn, message.Header.Flags)
if err != nil { if err != nil {
return nil, fmt.Errorf("Receive: %v", err) return nil, fmt.Errorf("receiveAckAware: %v", err)
} }
var sets []*Set var sets []*Set
for _, msg := range reply { for _, msg := range reply {
@ -877,11 +877,11 @@ func (cc *Conn) GetSetByName(t *Table, name string) (*Set, error) {
reply, err := receiveAckAware(conn, message.Header.Flags) reply, err := receiveAckAware(conn, message.Header.Flags)
if err != nil { if err != nil {
return nil, fmt.Errorf("Receive: %w", err) return nil, fmt.Errorf("receiveAckAware: %w", err)
} }
if len(reply) != 1 { if len(reply) != 1 {
return nil, fmt.Errorf("Receive: expected to receive 1 message but got %d", len(reply)) return nil, fmt.Errorf("receiveAckAware: expected to receive 1 message but got %d", len(reply))
} }
rs, err := setsFromMsg(reply[0]) rs, err := setsFromMsg(reply[0])
if err != nil { if err != nil {
@ -922,7 +922,7 @@ func (cc *Conn) GetSetElements(s *Set) ([]SetElement, error) {
reply, err := receiveAckAware(conn, message.Header.Flags) reply, err := receiveAckAware(conn, message.Header.Flags)
if err != nil { if err != nil {
return nil, fmt.Errorf("Receive: %v", err) return nil, fmt.Errorf("receiveAckAware: %v", err)
} }
var elems []SetElement var elems []SetElement
for _, msg := range reply { for _, msg := range reply {