Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linter: fixes for staticcheck #27

Merged
merged 1 commit into from
Sep 28, 2022
Merged
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
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading