Skip to content

Commit

Permalink
linter: fixes for staticcheck (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
sknat committed Sep 28, 2022
1 parent 5605f69 commit fd89a9c
Show file tree
Hide file tree
Showing 41 changed files with 330 additions and 407 deletions.
10 changes: 6 additions & 4 deletions Makefile
Expand Up @@ -82,10 +82,12 @@ test-integration: ## Run integration tests
@echo "# running integration tests"
go test -tags="integration ${GO_BUILD_TAGS}" ./test/integration

.PHONY: lint
lint: ## Run code linter
@echo "# running linter"
@golint ./...
.PHONY: lint ## Run code linter
lint:
@gofmt -s -l . | diff -u /dev/null -
@go vet ./...
@golangci-lint run
@echo "Done"

.PHONY: install
install: install-generator install-proxy ## Install all
Expand Down
16 changes: 8 additions & 8 deletions adapter/mock/mock_vpp_adapter.go
Expand Up @@ -356,17 +356,17 @@ func (a *VppAdapter) WaitReady() error {
// exactly two calls of this method.
// For example:
//
// mockVpp.MockReply( // push multipart messages all at once
// &interfaces.SwInterfaceDetails{SwIfIndex:1},
// &interfaces.SwInterfaceDetails{SwIfIndex:2},
// &interfaces.SwInterfaceDetails{SwIfIndex:3},
// )
// mockVpp.MockReply(&vpe.ControlPingReply{})
// mockVpp.MockReply( // push multipart messages all at once
// &interfaces.SwInterfaceDetails{SwIfIndex:1},
// &interfaces.SwInterfaceDetails{SwIfIndex:2},
// &interfaces.SwInterfaceDetails{SwIfIndex:3},
// )
// mockVpp.MockReply(&vpe.ControlPingReply{})
//
// Even if the multipart request has no replies, MockReply has to be called twice:
//
// mockVpp.MockReply() // zero multipart messages
// mockVpp.MockReply(&vpe.ControlPingReply{})
// mockVpp.MockReply() // zero multipart messages
// mockVpp.MockReply(&vpe.ControlPingReply{})
func (a *VppAdapter) MockReply(msgs ...api.Message) {
a.repliesLock.Lock()
defer a.repliesLock.Unlock()
Expand Down
4 changes: 1 addition & 3 deletions adapter/socketclient/doc.go
Expand Up @@ -18,8 +18,7 @@
// The current implementation only supports VPP binary API, the VPP stats API
// is not supported and clients still have to use vppapiclient for retrieving stats.
//
//
// Requirements
// # Requirements
//
// The socketclient connects to unix domain socket defined in VPP configuration.
//
Expand All @@ -34,5 +33,4 @@
// socksvr {
// socket-name /run/vpp/api.sock
// }
//
package socketclient
38 changes: 20 additions & 18 deletions adapter/socketclient/socketclient.go
Expand Up @@ -108,7 +108,8 @@ func NewVppClient(socket string) *Client {
connectTimeout: DefaultConnectTimeout,
disconnectTimeout: DefaultDisconnectTimeout,
headerPool: &sync.Pool{New: func() interface{} {
return make([]byte, 16)
x := make([]byte, 16)
return &x
}},
msgCallback: func(msgID uint16, data []byte) {
log.Debugf("no callback set, dropping message: ID=%v len=%d", msgID, len(data))
Expand Down Expand Up @@ -358,12 +359,11 @@ func (c *Client) SendMsg(context uint32, data []byte) error {
//
// Message request has following structure:
//
// type msgRequestHeader struct {
// MsgID uint16
// ClientIndex uint32
// Context uint32
// }
//
// type msgRequestHeader struct {
// MsgID uint16
// ClientIndex uint32
// Context uint32
// }
func setMsgRequestHeader(data []byte, clientIndex, context uint32) {
// message ID is already set
binary.BigEndian.PutUint32(data[2:6], clientIndex)
Expand All @@ -375,12 +375,12 @@ func (c *Client) writeMsg(msg []byte) error {
c.writeMu.Lock()
defer c.writeMu.Unlock()

header := c.headerPool.Get().([]byte)
err := writeMsgHeader(c.writer, header, len(msg))
header := c.headerPool.Get().(*[]byte)
err := writeMsgHeader(c.writer, *header, len(msg))
if err != nil {
return err
}
c.headerPool.Put(header)
c.headerPool.Put(&header)

if err := writeMsgData(c.writer, msg, c.writer.Size()); err != nil {
return err
Expand Down Expand Up @@ -464,11 +464,10 @@ func (c *Client) readerLoop() {
//
// Message reply has following structure:
//
// type msgReplyHeader struct {
// MsgID uint16
// Context uint32
// }
//
// type msgReplyHeader struct {
// MsgID uint16
// Context uint32
// }
func getMsgReplyHeader(msg []byte) (msgID uint16, context uint32) {
msgID = binary.BigEndian.Uint16(msg[0:2])
context = binary.BigEndian.Uint32(msg[2:6])
Expand Down Expand Up @@ -499,14 +498,17 @@ func (c *Client) readMsgTimeout(buf []byte, timeout time.Duration) ([]byte, erro
func (c *Client) readMsg(buf []byte) ([]byte, error) {
log.Debug("reading msg..")

header := c.headerPool.Get().([]byte)
msgLen, err := readMsgHeader(c.reader, header)
header := c.headerPool.Get().(*[]byte)
msgLen, err := readMsgHeader(c.reader, *header)
if err != nil {
return nil, err
}
c.headerPool.Put(header)
c.headerPool.Put(&header)

msg, err := readMsgData(c.reader, buf, msgLen)
if err != nil {
return nil, err
}

log.Debugf(" -- readMsg done (buffered: %d)", c.reader.Buffered())

Expand Down
4 changes: 2 additions & 2 deletions adapter/statsclient/statsclient.go
Expand Up @@ -26,10 +26,10 @@ import (
"syscall"
"time"

"go.fd.io/govpp/adapter"
"github.com/fsnotify/fsnotify"
"github.com/ftrvxmtrx/fd"
logger "github.com/sirupsen/logrus"
"go.fd.io/govpp/adapter"
)

const (
Expand Down Expand Up @@ -610,7 +610,7 @@ func (sc *StatsClient) updateStatOnIndex(entry *adapter.StatEntry, vector dirVec
return nil
}
if err := sc.UpdateEntryData(dirPtr, &entry.Data); err != nil {
err = fmt.Errorf("updating stat data for entry %s failed: %v", dirName, err)
return fmt.Errorf("updating stat data for entry %s failed: %v", dirName, err)
}
return
}
5 changes: 0 additions & 5 deletions adapter/statsclient/statseg_v1.go
Expand Up @@ -15,7 +15,6 @@
package statsclient

import (
"fmt"
"sync/atomic"
"unsafe"

Expand Down Expand Up @@ -71,10 +70,6 @@ func (ss *statSegmentV1) GetDirectoryVector() dirVector {
return dirVector(&ss.sharedHeader[dirOffset])
}

func (ss *statSegmentV1) getErrorVector() (unsafe.Pointer, error) {
return nil, fmt.Errorf("error vector is not defined for stats API v1")
}

func (ss *statSegmentV1) GetStatDirOnIndex(v dirVector, index uint32) (dirSegment, dirName, adapter.StatType) {
statSegDir := dirSegment(uintptr(v) + uintptr(index)*unsafe.Sizeof(statSegDirectoryEntryV1{}))
dir := (*statSegDirectoryEntryV1)(statSegDir)
Expand Down

0 comments on commit fd89a9c

Please sign in to comment.