Skip to content

Commit 3054d1d

Browse files
author
Al S-M
authored
Merge pull request eclipse-paho#407 from thomas-tacquet/code-consitency-fixes
Code consitency fixes
2 parents 0d940dd + 07861f1 commit 3054d1d

11 files changed

+42
-42
lines changed

client.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ func (c *client) connectionStatus() uint32 {
198198
func (c *client) setConnected(status uint32) {
199199
c.Lock()
200200
defer c.Unlock()
201-
atomic.StoreUint32(&c.status, uint32(status))
201+
atomic.StoreUint32(&c.status, status)
202202
}
203203

204204
//ErrNotConnected is the error returned from function calls that are
205205
//made when the client is not connected to a broker
206-
var ErrNotConnected = errors.New("Not Connected")
206+
var ErrNotConnected = errors.New("not Connected")
207207

208208
// Connect will create a connection to the message broker, by default
209209
// it will attempt to connect at v3.1.1 and auto retry at v3.1 if that
@@ -241,7 +241,7 @@ func (c *client) Connect() Token {
241241
protocolVersion := c.options.ProtocolVersion
242242

243243
if len(c.options.Servers) == 0 {
244-
t.setError(fmt.Errorf("No servers defined to connect to"))
244+
t.setError(fmt.Errorf("no servers defined to connect to"))
245245
return
246246
}
247247

@@ -376,7 +376,7 @@ func (c *client) reconnect() {
376376
err error
377377

378378
rc = byte(1)
379-
sleep = time.Duration(1 * time.Second)
379+
sleep = 1 * time.Second
380380
)
381381

382382
for rc != 0 && atomic.LoadUint32(&c.status) != disconnected {
@@ -632,7 +632,7 @@ func (c *client) Publish(topic string, qos byte, retained bool, payload interfac
632632
case bytes.Buffer:
633633
pub.Payload = p.Bytes()
634634
default:
635-
token.setError(fmt.Errorf("Unknown payload type"))
635+
token.setError(fmt.Errorf("unknown payload type"))
636636
return token
637637
}
638638

fvt_client_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ func Test_autoreconnect(t *testing.T) {
10131013
time.Sleep(5 * time.Second)
10141014

10151015
fmt.Println("Breaking connection")
1016-
c.(*client).internalConnLost(fmt.Errorf("Autoreconnect test"))
1016+
c.(*client).internalConnLost(fmt.Errorf("autoreconnect test"))
10171017

10181018
time.Sleep(5 * time.Second)
10191019
if !c.IsConnected() {
@@ -1323,7 +1323,7 @@ func Test_ResumeSubsWithReconnect(t *testing.T) {
13231323

13241324
persistOutbound(c.(*client).persist, sub)
13251325
//subToken := c.Subscribe(topic, qos, nil)
1326-
c.(*client).internalConnLost(fmt.Errorf("Reconnection subscription test"))
1326+
c.(*client).internalConnLost(fmt.Errorf("reconnection subscription test"))
13271327

13281328
// As reconnect is enabled the client should automatically reconnect
13291329
subDone := make(chan bool)

memstore.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (store *MemoryStore) All() []string {
8888
ERROR.Println(STR, "Trying to use memory store, but not open")
8989
return nil
9090
}
91-
keys := []string{}
91+
var keys []string
9292
for k := range store.messages {
9393
keys = append(keys, k)
9494
}

messageids.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ func (mids *messageIds) cleanUp() {
4040
for _, token := range mids.index {
4141
switch token.(type) {
4242
case *PublishToken:
43-
token.setError(fmt.Errorf("Connection lost before Publish completed"))
43+
token.setError(fmt.Errorf("connection lost before Publish completed"))
4444
case *SubscribeToken:
45-
token.setError(fmt.Errorf("Connection lost before Subscribe completed"))
45+
token.setError(fmt.Errorf("connection lost before Subscribe completed"))
4646
case *UnsubscribeToken:
47-
token.setError(fmt.Errorf("Connection lost before Unsubscribe completed"))
47+
token.setError(fmt.Errorf("connection lost before Unsubscribe completed"))
4848
case nil:
4949
continue
5050
}
@@ -114,7 +114,7 @@ func (d *DummyToken) Error() error {
114114
return nil
115115
}
116116

117-
func (p *DummyToken) setError(e error) {}
117+
func (d *DummyToken) setError(e error) {}
118118

119119
// PlaceHolderToken does nothing and was implemented to allow a messageid to be reserved
120120
// it differs from DummyToken in that calling flowComplete does not generate an error (it

net.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func openConnection(uri *url.URL, tlsc *tls.Config, timeout time.Duration, heade
9696

9797
return tlsConn, nil
9898
}
99-
return nil, errors.New("Unknown protocol")
99+
return nil, errors.New("unknown protocol")
100100
}
101101

102102
// actually read incoming messages off the wire

packets/packets.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ var ConnackReturnCodes = map[uint8]string{
8585
//to a Go error
8686
var ConnErrors = map[byte]error{
8787
Accepted: nil,
88-
ErrRefusedBadProtocolVersion: errors.New("Unnacceptable protocol version"),
89-
ErrRefusedIDRejected: errors.New("Identifier rejected"),
90-
ErrRefusedServerUnavailable: errors.New("Server Unavailable"),
91-
ErrRefusedBadUsernameOrPassword: errors.New("Bad user name or password"),
92-
ErrRefusedNotAuthorised: errors.New("Not Authorized"),
93-
ErrNetworkError: errors.New("Network Error"),
94-
ErrProtocolViolation: errors.New("Protocol Violation"),
88+
ErrRefusedBadProtocolVersion: errors.New("unnacceptable protocol version"),
89+
ErrRefusedIDRejected: errors.New("identifier rejected"),
90+
ErrRefusedServerUnavailable: errors.New("server Unavailable"),
91+
ErrRefusedBadUsernameOrPassword: errors.New("bad user name or password"),
92+
ErrRefusedNotAuthorised: errors.New("not Authorized"),
93+
ErrNetworkError: errors.New("network Error"),
94+
ErrProtocolViolation: errors.New("protocol Violation"),
9595
}
9696

9797
//ReadPacket takes an instance of an io.Reader (such as net.Conn) and attempts
@@ -123,7 +123,7 @@ func ReadPacket(r io.Reader) (ControlPacket, error) {
123123
return nil, err
124124
}
125125
if n != fh.RemainingLength {
126-
return nil, errors.New("Failed to read expected data")
126+
return nil, errors.New("failed to read expected data")
127127
}
128128

129129
err = cp.Unpack(bytes.NewBuffer(packetBytes))
@@ -274,9 +274,9 @@ func decodeUint16(b io.Reader) (uint16, error) {
274274
}
275275

276276
func encodeUint16(num uint16) []byte {
277-
bytes := make([]byte, 2)
278-
binary.BigEndian.PutUint16(bytes, num)
279-
return bytes
277+
bytesResult := make([]byte, 2)
278+
binary.BigEndian.PutUint16(bytesResult, num)
279+
return bytesResult
280280
}
281281

282282
func encodeString(field string) []byte {

packets/packets_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ func TestEncoding(t *testing.T) {
203203
}
204204

205205
strings := map[string][]byte{
206-
"foo": []byte{0x00, 0x03, 'f', 'o', 'o'},
207-
"\U0000FEFF": []byte{0x00, 0x03, 0xEF, 0xBB, 0xBF},
208-
"A\U0002A6D4": []byte{0x00, 0x05, 'A', 0xF0, 0xAA, 0x9B, 0x94},
206+
"foo": {0x00, 0x03, 'f', 'o', 'o'},
207+
"\U0000FEFF": {0x00, 0x03, 0xEF, 0xBB, 0xBF},
208+
"A\U0002A6D4": {0x00, 0x05, 'A', 0xF0, 0xAA, 0x9B, 0x94},
209209
}
210210
for str, encoded := range strings {
211211
if res, err := decodeString(bytes.NewBuffer(encoded)); res != str || err != nil {
@@ -217,14 +217,14 @@ func TestEncoding(t *testing.T) {
217217
}
218218

219219
lengths := map[int][]byte{
220-
0: []byte{0x00},
221-
127: []byte{0x7F},
222-
128: []byte{0x80, 0x01},
223-
16383: []byte{0xFF, 0x7F},
224-
16384: []byte{0x80, 0x80, 0x01},
225-
2097151: []byte{0xFF, 0xFF, 0x7F},
226-
2097152: []byte{0x80, 0x80, 0x80, 0x01},
227-
268435455: []byte{0xFF, 0xFF, 0xFF, 0x7F},
220+
0: {0x00},
221+
127: {0x7F},
222+
128: {0x80, 0x01},
223+
16383: {0xFF, 0x7F},
224+
16384: {0x80, 0x80, 0x01},
225+
2097151: {0xFF, 0xFF, 0x7F},
226+
2097152: {0x80, 0x80, 0x80, 0x01},
227+
268435455: {0xFF, 0xFF, 0xFF, 0x7F},
228228
}
229229
for length, encoded := range lengths {
230230
if res, err := decodeLength(bytes.NewBuffer(encoded)); res != length || err != nil {

packets/publish.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (p *PublishPacket) Unpack(b io.Reader) error {
5656
payloadLength -= len(p.TopicName) + 2
5757
}
5858
if payloadLength < 0 {
59-
return fmt.Errorf("Error unpacking publish, payload length < 0")
59+
return fmt.Errorf("error unpacking publish, payload length < 0")
6060
}
6161
p.Payload = make([]byte, payloadLength)
6262
_, err = b.Read(p.Payload)

router.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (r *router) matchAndDispatch(messages <-chan *packets.PublishPacket, order
141141
sent := false
142142
r.RLock()
143143
m := messageFromPublish(message, client.ackFunc(message))
144-
handlers := []MessageHandler{}
144+
var handlers []MessageHandler
145145
for e := r.routes.Front(); e != nil; e = e.Next() {
146146
if e.Value.(*route).match(message.TopicName) {
147147
if order {

topic.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ import (
2121

2222
//ErrInvalidQos is the error returned when an packet is to be sent
2323
//with an invalid Qos value
24-
var ErrInvalidQos = errors.New("Invalid QoS")
24+
var ErrInvalidQos = errors.New("invalid QoS")
2525

2626
//ErrInvalidTopicEmptyString is the error returned when a topic string
2727
//is passed in that is 0 length
28-
var ErrInvalidTopicEmptyString = errors.New("Invalid Topic; empty string")
28+
var ErrInvalidTopicEmptyString = errors.New("invalid Topic; empty string")
2929

3030
//ErrInvalidTopicMultilevel is the error returned when a topic string
3131
//is passed in that has the multi level wildcard in any position but
3232
//the last
33-
var ErrInvalidTopicMultilevel = errors.New("Invalid Topic; multi-level wildcard must be last level")
33+
var ErrInvalidTopicMultilevel = errors.New("invalid Topic; multi-level wildcard must be last level")
3434

3535
// Topic Names and Topic Filters
3636
// The MQTT v3.1.1 spec clarifies a number of ambiguities with regard
@@ -51,7 +51,7 @@ var ErrInvalidTopicMultilevel = errors.New("Invalid Topic; multi-level wildcard
5151

5252
func validateSubscribeMap(subs map[string]byte) ([]string, []byte, error) {
5353
if len(subs) == 0 {
54-
return nil, nil, errors.New("Invalid subscription; subscribe map must not be empty")
54+
return nil, nil, errors.New("invalid subscription; subscribe map must not be empty")
5555
}
5656

5757
var topics []string

unit_store_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func Test_exists_no(t *testing.T) {
4646

4747
func isemptydir(dir string) bool {
4848
if !exists(dir) {
49-
panic(fmt.Errorf("Directory %s does not exist", dir))
49+
panic(fmt.Errorf("directory %s does not exist", dir))
5050
}
5151
files, err := ioutil.ReadDir(dir)
5252
chkerr(err)

0 commit comments

Comments
 (0)