Skip to content

Commit

Permalink
update golangci-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Apr 28, 2024
1 parent 19c796a commit d448f3a
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 55 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,3 @@ linters-settings:
disable:
- fieldalignment
- reflectvaluecompare
- shadow
4 changes: 2 additions & 2 deletions action_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ func TestActionClient(t *testing.T) {
},
OnTransition: func(gh *ActionClientGoalHandler, res *DoSomethingActionResult) {
if gh.CommState() == ActionClientCommStateDone {
ts, err := gh.TerminalState()
require.NoError(t, err)
ts, err2 := gh.TerminalState()
require.NoError(t, err2)

switch ca {
case "rejected":
Expand Down
4 changes: 2 additions & 2 deletions pkg/apimaster/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func TestClientErrors(t *testing.T) {

case "unregisterSubscriber":
var req RequestUnregister
err := raw.Decode(&req)
err = raw.Decode(&req)
require.NoError(t, err)
if req.Topic == "mytopic" {
return ResponseUnregister{Code: 0, NumUnregistered: 1}
Expand All @@ -246,7 +246,7 @@ func TestClientErrors(t *testing.T) {

case "unregisterService":
var req RequestUnregisterService
err := raw.Decode(&req)
err = raw.Decode(&req)
require.NoError(t, err)
if req.Service == "myservice" {
return ResponseServiceUnregister{Code: 0, NumUnregistered: 1}
Expand Down
4 changes: 2 additions & 2 deletions pkg/apiparam/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func TestClientError(t *testing.T) {

case "getParam":
var req RequestGetParam
err := raw.Decode(&req)
err = raw.Decode(&req)
require.NoError(t, err)

switch req.Key {
Expand All @@ -223,7 +223,7 @@ func TestClientError(t *testing.T) {

case "hasParam":
var req RequestHasParam
err := raw.Decode(&req)
err = raw.Decode(&req)
require.NoError(t, err)

if req.Key == "mykey" {
Expand Down
4 changes: 3 additions & 1 deletion pkg/conversion/message_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ func parseMessageDefinition(rosPkgName string, name string, content string) (*me
if i < 0 {
return nil, fmt.Errorf("unable to parse line (%s)", line)
}
typ, line := line[:i], line[i+1:]

var typ string
typ, line = line[:i], line[i+1:]

line = strings.TrimLeft(line, " \t")

Expand Down
2 changes: 1 addition & 1 deletion pkg/xmlrpc/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func requestEncode(w io.Writer, method string, params interface{}) error {
for i := 0; i < nf; i++ {
field := rv.Field(i)

_, err := w.Write([]byte(`<param>`))
_, err = w.Write([]byte(`<param>`))
if err != nil {
return err
}
Expand Down
14 changes: 9 additions & 5 deletions pkg/xmlrpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestServer(t *testing.T) {
go s.Serve(func(raw *RequestRaw) interface{} {
if raw.Method == "mymethod" {
var req myRequest
err := raw.Decode(&req)
err = raw.Decode(&req)
require.NoError(t, err)
return myResponse{Param: "myresponse"}
}
Expand All @@ -40,7 +40,8 @@ func TestServer(t *testing.T) {
err = requestEncode(&buf, "mymethod", myRequest{Param: "myrequest"})
require.NoError(t, err)

res, err := http.Post("http://localhost:9904/RPC2", "text/xml", &buf)
var res *http.Response
res, err = http.Post("http://localhost:9904/RPC2", "text/xml", &buf)
require.NoError(t, err)
defer res.Body.Close()

Expand All @@ -51,14 +52,16 @@ func TestServer(t *testing.T) {
})

t.Run("wrong path", func(t *testing.T) {
res, err := http.Post("http://localhost:9904/wrong", "text/xml", nil)
var res *http.Response
res, err = http.Post("http://localhost:9904/wrong", "text/xml", nil)
require.NoError(t, err)
defer res.Body.Close()
require.Equal(t, 404, res.StatusCode)
})

t.Run("wrong method", func(t *testing.T) {
res, err := http.Get("http://localhost:9904/RPC2")
var res *http.Response
res, err = http.Get("http://localhost:9904/RPC2")
require.NoError(t, err)
defer res.Body.Close()
require.Equal(t, 404, res.StatusCode)
Expand All @@ -67,7 +70,8 @@ func TestServer(t *testing.T) {
t.Run("invalid request", func(t *testing.T) {
var buf bytes.Buffer
buf.WriteString("wrong")
res, err := http.Post("http://localhost:9904/RPC2", "text/xml", &buf)
var res *http.Response
res, err = http.Post("http://localhost:9904/RPC2", "text/xml", &buf)
require.NoError(t, err)
defer res.Body.Close()
require.Equal(t, 400, res.StatusCode)
Expand Down
33 changes: 19 additions & 14 deletions pkg/xmlrpc/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ func valueDecode(dec *xml.Decoder, dest reflect.Value) error {
case xml.StartElement:
switch ttok.Name.Local {
case "boolean":
cnt, err := xmlGetContent(dec)
var cnt []byte
cnt, err = xmlGetContent(dec)
if err != nil {
return err
}
Expand All @@ -200,7 +201,8 @@ func valueDecode(dec *xml.Decoder, dest reflect.Value) error {
}

case "int", "i4":
cnt, err := xmlGetContent(dec)
var cnt []byte
cnt, err = xmlGetContent(dec)
if err != nil {
return err
}
Expand All @@ -211,7 +213,8 @@ func valueDecode(dec *xml.Decoder, dest reflect.Value) error {
}

case "double":
cnt, err := xmlGetContent(dec)
var cnt []byte
cnt, err = xmlGetContent(dec)
if err != nil {
return err
}
Expand All @@ -222,7 +225,8 @@ func valueDecode(dec *xml.Decoder, dest reflect.Value) error {
}

case "string":
cnt, err := xmlGetContent(dec)
var cnt []byte
cnt, err = xmlGetContent(dec)
if err != nil {
return err
}
Expand All @@ -233,7 +237,8 @@ func valueDecode(dec *xml.Decoder, dest reflect.Value) error {
}

case "base64":
cnt, err := xmlGetContent(dec)
var cnt []byte
cnt, err = xmlGetContent(dec)
if err != nil {
return err
}
Expand Down Expand Up @@ -296,39 +301,39 @@ func valueEncode(w io.Writer, src reflect.Value) error {
if tval {
v = "1"
}
_, err := w.Write([]byte(`<boolean>` + v + `</boolean>`))
_, err = w.Write([]byte(`<boolean>` + v + `</boolean>`))
if err != nil {
return err
}

case int:
_, err := w.Write([]byte(`<i4>` + strconv.FormatInt(int64(tval), 10) + `</i4>`))
_, err = w.Write([]byte(`<i4>` + strconv.FormatInt(int64(tval), 10) + `</i4>`))
if err != nil {
return err
}

case float64:
_, err := w.Write([]byte(`<double>` + strconv.FormatFloat(tval, 'G', -1, 64) + `</double>`))
_, err = w.Write([]byte(`<double>` + strconv.FormatFloat(tval, 'G', -1, 64) + `</double>`))
if err != nil {
return err
}

case string:
_, err := w.Write([]byte(tval))
_, err = w.Write([]byte(tval))
if err != nil {
return err
}

case []byte:
_, err := w.Write([]byte(`<base64>` + base64.StdEncoding.EncodeToString(tval) + `</base64>`))
_, err = w.Write([]byte(`<base64>` + base64.StdEncoding.EncodeToString(tval) + `</base64>`))
if err != nil {
return err
}

default:
switch src.Kind() {
case reflect.Struct:
_, err := w.Write([]byte(`<array><data>`))
_, err = w.Write([]byte(`<array><data>`))
if err != nil {
return err
}
Expand All @@ -337,7 +342,7 @@ func valueEncode(w io.Writer, src reflect.Value) error {
for i := 0; i < nf; i++ {
field := src.Field(i)

err := valueEncode(w, field)
err = valueEncode(w, field)
if err != nil {
return err
}
Expand All @@ -349,7 +354,7 @@ func valueEncode(w io.Writer, src reflect.Value) error {
}

case reflect.Slice:
_, err := w.Write([]byte(`<array><data>`))
_, err = w.Write([]byte(`<array><data>`))
if err != nil {
return err
}
Expand All @@ -358,7 +363,7 @@ func valueEncode(w io.Writer, src reflect.Value) error {
for i := 0; i < le; i++ {
el := src.Index(i)

err := valueEncode(w, el)
err = valueEncode(w, el)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions service_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func TestServiceClientRequestAfterProvider(t *testing.T) {
B: "456",
}
var res TestServiceRes
err := sc.Call(&req, &res)
require.NoError(t, err)
err2 := sc.Call(&req, &res)
require.NoError(t, err2)

expected := TestServiceRes{C: 123}
require.Equal(t, expected, res)
Expand Down
6 changes: 4 additions & 2 deletions service_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ func TestServiceProviderResponse(t *testing.T) {

switch client {
case "cpp", "go":
sp, err := NewServiceProvider(ServiceProviderConf{
var sp *ServiceProvider
sp, err = NewServiceProvider(ServiceProviderConf{
Node: nsp,
Name: "test_srv",
Srv: &TestService{},
Expand All @@ -136,7 +137,8 @@ func TestServiceProviderResponse(t *testing.T) {
defer sp.Close()

case "rosservice call":
sp, err := NewServiceProvider(ServiceProviderConf{
var sp *ServiceProvider
sp, err = NewServiceProvider(ServiceProviderConf{
Node: nsp,
Name: "test_srv",
Srv: &std_srvs.SetBool{},
Expand Down
4 changes: 2 additions & 2 deletions subscriber_pub.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (sp *subscriberPublisher) runInner() error {
requestedProtos = [][]interface{}{{"TCPROS"}}
} else {
var buf bytes.Buffer
err := protocommon.HeaderEncode(&buf, &protoudp.HeaderSubscriber{
err = protocommon.HeaderEncode(&buf, &protoudp.HeaderSubscriber{
Callerid: sp.sub.conf.Node.absoluteName(),
Md5sum: sp.sub.msgMd5,
Topic: sp.sub.conf.Node.absoluteTopicName(sp.sub.conf.Topic),
Expand Down Expand Up @@ -230,7 +230,7 @@ func (sp *subscriberPublisher) runInnerTCP(proto []interface{}) error {
}

if sp.sub.conf.DisableNoDelay {
err := nconn.(*net.TCPConn).SetNoDelay(false)
err = nconn.(*net.TCPConn).SetNoDelay(false)
if err != nil {
return err
}
Expand Down
42 changes: 21 additions & 21 deletions subscriber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ func newTestPublisher(t *testing.T, masterIP string,
require.NoError(t, err)

go func() {
nconn, err := tcprosListener.Accept()
require.NoError(t, err)
nconn, err2 := tcprosListener.Accept()
require.NoError(t, err2)
defer nconn.Close()
tconn := prototcp.NewConn(nconn)

rawHeader, err := tconn.ReadHeaderRaw()
require.NoError(t, err)
rawHeader, err2 := tconn.ReadHeaderRaw()
require.NoError(t, err2)

var header prototcp.HeaderSubscriber
err = protocommon.HeaderDecode(rawHeader, &header)
require.NoError(t, err)
err2 = protocommon.HeaderDecode(rawHeader, &header)
require.NoError(t, err2)

cb(header, tconn)
}()
Expand Down Expand Up @@ -448,30 +448,30 @@ func TestSubscriberReadUDP(t *testing.T) {
protoHost := req2.Protocols[0][2].(string)
protoPort := req2.Protocols[0][3].(int)

msgMd5, err := msgproc.MD5(std_msgs.Int64MultiArray{})
var msgMd5 string
msgMd5, err = msgproc.MD5(std_msgs.Int64MultiArray{})
require.NoError(t, err)

udpAddr, err := net.ResolveUDPAddr("udp",
var udpAddr *net.UDPAddr
udpAddr, err = net.ResolveUDPAddr("udp",
net.JoinHostPort(protoHost, strconv.FormatInt(int64(protoPort), 10)))
require.NoError(t, err)

go func() {
time.Sleep(1 * time.Second)
err := uconn.WriteMessage(1, 1, &expected, udpAddr)
require.NoError(t, err)
err2 := uconn.WriteMessage(1, 1, &expected, udpAddr)
require.NoError(t, err2)
}()

udpHeader := func() []byte {
var buf bytes.Buffer
err := protocommon.HeaderEncode(&buf, &protoudp.HeaderPublisher{
Callerid: "/myns/goroslib_pub",
Md5sum: msgMd5,
Topic: "/myns/test_topic",
Type: "std_msgs/Int64MultiArray",
})
require.NoError(t, err)
return buf.Bytes()[4:]
}()
var buf bytes.Buffer
err = protocommon.HeaderEncode(&buf, &protoudp.HeaderPublisher{
Callerid: "/myns/goroslib_pub",
Md5sum: msgMd5,
Topic: "/myns/test_topic",
Type: "std_msgs/Int64MultiArray",
})
require.NoError(t, err)
udpHeader := buf.Bytes()[4:]

return apislave.ResponseRequestTopic{
Code: 1,
Expand Down

0 comments on commit d448f3a

Please sign in to comment.