Skip to content

Commit a5e6d31

Browse files
committed
code health: fix all places highlighted by linter
Relates to #142
1 parent 7897baf commit a5e6d31

13 files changed

+76
-26
lines changed

client_tools.go

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type IntKey struct {
1010
I int
1111
}
1212

13+
//nolint: errcheck
1314
func (k IntKey) EncodeMsgpack(enc *msgpack.Encoder) error {
1415
enc.EncodeSliceLen(1)
1516
enc.EncodeInt(k.I)
@@ -22,6 +23,7 @@ type UintKey struct {
2223
I uint
2324
}
2425

26+
//nolint: errcheck
2527
func (k UintKey) EncodeMsgpack(enc *msgpack.Encoder) error {
2628
enc.EncodeSliceLen(1)
2729
enc.EncodeUint(k.I)
@@ -34,6 +36,7 @@ type StringKey struct {
3436
S string
3537
}
3638

39+
//nolint: errcheck
3740
func (k StringKey) EncodeMsgpack(enc *msgpack.Encoder) error {
3841
enc.EncodeSliceLen(1)
3942
enc.EncodeString(k.S)
@@ -46,6 +49,7 @@ type IntIntKey struct {
4649
I1, I2 int
4750
}
4851

52+
//nolint: errcheck
4953
func (k IntIntKey) EncodeMsgpack(enc *msgpack.Encoder) error {
5054
enc.EncodeSliceLen(2)
5155
enc.EncodeInt(k.I1)
@@ -60,6 +64,7 @@ type Op struct {
6064
Arg interface{}
6165
}
6266

67+
//nolint: errcheck
6368
func (o Op) EncodeMsgpack(enc *msgpack.Encoder) error {
6469
enc.EncodeSliceLen(3)
6570
enc.EncodeString(o.Op)
@@ -75,6 +80,7 @@ type OpSplice struct {
7580
Replace string
7681
}
7782

83+
//nolint: errcheck
7884
func (o OpSplice) EncodeMsgpack(enc *msgpack.Encoder) error {
7985
enc.EncodeSliceLen(5)
8086
enc.EncodeString(o.Op)

connection.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ type connShard struct {
145145
bufmut sync.Mutex
146146
buf smallWBuf
147147
enc *msgpack.Encoder
148-
_pad [16]uint64
148+
_pad [16]uint64 //nolint: structcheck,unused
149149
}
150150

151151
// Greeting is a message sent by tarantool on connect.
@@ -227,6 +227,7 @@ type Opts struct {
227227
//
228228
// - If opts.Reconnect is non-zero, then error will be returned only if authorization// fails. But if Tarantool is not reachable, then it will attempt to reconnect later
229229
// and will not end attempts on authorization failures.
230+
//nolint: errcheck
230231
func Connect(addr string, opts Opts) (conn *Connection, err error) {
231232
conn = &Connection{
232233
addr: addr,
@@ -494,7 +495,7 @@ func (conn *Connection) createConnection(reconnect bool) (err error) {
494495
conn.notify(ReconnectFailed)
495496
reconnects++
496497
conn.mutex.Unlock()
497-
time.Sleep(now.Add(conn.opts.Reconnect).Sub(time.Now()))
498+
time.Sleep(time.Until(now.Add(conn.opts.Reconnect)))
498499
conn.mutex.Lock()
499500
}
500501
if conn.state == connClosed {
@@ -537,6 +538,7 @@ func (conn *Connection) closeConnection(neterr error, forever bool) (err error)
537538
return
538539
}
539540

541+
//nolint: errcheck
540542
func (conn *Connection) reconnect(neterr error, c net.Conn) {
541543
conn.mutex.Lock()
542544
defer conn.mutex.Unlock()
@@ -566,6 +568,7 @@ func (conn *Connection) unlockShards() {
566568
}
567569
}
568570

571+
//nolint: errcheck
569572
func (conn *Connection) pinger() {
570573
to := conn.opts.Timeout
571574
if to == 0 {
@@ -687,7 +690,7 @@ func (conn *Connection) newFuture(requestCode int32) (fut *Future) {
687690
*pair.last = fut
688691
pair.last = &fut.next
689692
if conn.opts.Timeout > 0 {
690-
fut.timeout = time.Now().Sub(epoch) + conn.opts.Timeout
693+
fut.timeout = time.Until(epoch) + conn.opts.Timeout
691694
}
692695
shard.rmut.Unlock()
693696
if conn.rlimit != nil && conn.opts.RLimitAction == RLimitWait {
@@ -795,9 +798,9 @@ func (conn *Connection) timeouts() {
795798
return
796799
case <-t.C:
797800
}
798-
minNext := time.Now().Sub(epoch) + timeout
801+
minNext := time.Until(epoch) + timeout
799802
for i := range conn.shard {
800-
nowepoch = time.Now().Sub(epoch)
803+
nowepoch = time.Until(epoch)
801804
shard := &conn.shard[i]
802805
for pos := range shard.requests {
803806
shard.rmut.Lock()
@@ -824,7 +827,7 @@ func (conn *Connection) timeouts() {
824827
shard.rmut.Unlock()
825828
}
826829
}
827-
nowepoch = time.Now().Sub(epoch)
830+
nowepoch = time.Until(epoch)
828831
if nowepoch+time.Microsecond < minNext {
829832
t.Reset(minNext - nowepoch)
830833
} else {

deadline_io.go

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type DeadlineIO struct {
1010
c net.Conn
1111
}
1212

13+
//nolint: errcheck
1314
func (d *DeadlineIO) Write(b []byte) (n int, err error) {
1415
if d.to > 0 {
1516
d.c.SetWriteDeadline(time.Now().Add(d.to))
@@ -18,6 +19,7 @@ func (d *DeadlineIO) Write(b []byte) (n int, err error) {
1819
return
1920
}
2021

22+
//nolint: errcheck
2123
func (d *DeadlineIO) Read(b []byte) (n int, err error) {
2224
if d.to > 0 {
2325
d.c.SetReadDeadline(time.Now().Add(d.to))

example_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
type Tuple struct {
1111
/* instruct msgpack to pack this struct as array,
1212
* so no custom packer is needed */
13-
_msgpack struct{} `msgpack:",asArray"`
13+
_msgpack struct{} `msgpack:",asArray"` //nolint: structcheck,unused
1414
Id uint
1515
Msg string
1616
Name string
@@ -85,6 +85,7 @@ func ExampleConnection_SelectTyped() {
8585
// response is [{{} 1111 hello world}]
8686
}
8787

88+
//nolint
8889
func Example() {
8990
spaceNo := uint32(512)
9091
indexNo := uint32(0)
@@ -99,7 +100,7 @@ func Example() {
99100
}
100101
client, err := tarantool.Connect(server, opts)
101102
if err != nil {
102-
fmt.Errorf("Failed to connect: %s", err.Error())
103+
fmt.Printf("Failed to connect: %s", err.Error())
103104
return
104105
}
105106

queue/example_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/tarantool/go-tarantool/queue"
99
)
1010

11+
//nolint
1112
func ExampleConnection_Queue() {
1213
cfg := queue.Cfg{
1314
Temporary: false,

queue/queue.go

+1
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ type queueData struct {
323323
result interface{}
324324
}
325325

326+
//nolint
326327
func (qd *queueData) DecodeMsgpack(d *msgpack.Decoder) error {
327328
var err error
328329
var l int

queue/queue_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -797,12 +797,14 @@ func TestUtube_Put(t *testing.T) {
797797
go func() {
798798
t1, err := q.TakeTimeout(2 * time.Second)
799799
if err != nil {
800-
t.Fatalf("Failed to take task from utube: %s", err.Error())
800+
t.Errorf("Failed to take task from utube: %s", err.Error())
801+
return
801802
}
802803

803804
time.Sleep(2 * time.Second)
804805
if err := t1.Ack(); err != nil {
805-
t.Fatalf("Failed to ack task: %s", err.Error())
806+
t.Errorf("Failed to ack task: %s", err.Error())
807+
return
806808
}
807809
}()
808810

request.go

+14
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ type Future struct {
1919
}
2020

2121
// Ping sends empty request to Tarantool to check connection.
22+
//nolint: errcheck
2223
func (conn *Connection) Ping() (resp *Response, err error) {
2324
future := conn.newFuture(PingRequest)
2425
return future.send(conn, func(enc *msgpack.Encoder) error { enc.EncodeMapLen(0); return nil }).Get()
2526
}
2627

28+
//nolint: errcheck
2729
func (req *Future) fillSearch(enc *msgpack.Encoder, spaceNo, indexNo uint32, key interface{}) error {
2830
enc.EncodeUint64(KeySpaceNo)
2931
enc.EncodeUint64(uint64(spaceNo))
@@ -33,6 +35,7 @@ func (req *Future) fillSearch(enc *msgpack.Encoder, spaceNo, indexNo uint32, key
3335
return enc.Encode(key)
3436
}
3537

38+
//nolint: errcheck
3639
func (req *Future) fillIterator(enc *msgpack.Encoder, offset, limit, iterator uint32) {
3740
enc.EncodeUint64(KeyIterator)
3841
enc.EncodeUint64(uint64(iterator))
@@ -42,6 +45,7 @@ func (req *Future) fillIterator(enc *msgpack.Encoder, offset, limit, iterator ui
4245
enc.EncodeUint64(uint64(limit))
4346
}
4447

48+
//nolint: errcheck
4549
func (req *Future) fillInsert(enc *msgpack.Encoder, spaceNo uint32, tuple interface{}) error {
4650
enc.EncodeUint64(KeySpaceNo)
4751
enc.EncodeUint64(uint64(spaceNo))
@@ -219,6 +223,7 @@ func (conn *Connection) SelectAsync(space, index interface{}, offset, limit, ite
219223
if err != nil {
220224
return future.fail(conn, err)
221225
}
226+
//nolint: errcheck
222227
return future.send(conn, func(enc *msgpack.Encoder) error {
223228
enc.EncodeMapLen(6)
224229
future.fillIterator(enc, offset, limit, iterator)
@@ -234,6 +239,7 @@ func (conn *Connection) InsertAsync(space interface{}, tuple interface{}) *Futur
234239
if err != nil {
235240
return future.fail(conn, err)
236241
}
242+
//nolint: errcheck
237243
return future.send(conn, func(enc *msgpack.Encoder) error {
238244
enc.EncodeMapLen(2)
239245
return future.fillInsert(enc, spaceNo, tuple)
@@ -248,6 +254,7 @@ func (conn *Connection) ReplaceAsync(space interface{}, tuple interface{}) *Futu
248254
if err != nil {
249255
return future.fail(conn, err)
250256
}
257+
//nolint: errcheck
251258
return future.send(conn, func(enc *msgpack.Encoder) error {
252259
enc.EncodeMapLen(2)
253260
return future.fillInsert(enc, spaceNo, tuple)
@@ -256,6 +263,7 @@ func (conn *Connection) ReplaceAsync(space interface{}, tuple interface{}) *Futu
256263

257264
// DeleteAsync sends deletion action to tarantool and returns Future.
258265
// Future's result will contain array with deleted tuple.
266+
//nolint: errcheck
259267
func (conn *Connection) DeleteAsync(space, index interface{}, key interface{}) *Future {
260268
future := conn.newFuture(DeleteRequest)
261269
spaceNo, indexNo, err := conn.Schema.resolveSpaceIndex(space, index)
@@ -276,6 +284,7 @@ func (conn *Connection) UpdateAsync(space, index interface{}, key, ops interface
276284
if err != nil {
277285
return future.fail(conn, err)
278286
}
287+
//nolint: errcheck
279288
return future.send(conn, func(enc *msgpack.Encoder) error {
280289
enc.EncodeMapLen(4)
281290
if err := future.fillSearch(enc, spaceNo, indexNo, key); err != nil {
@@ -294,6 +303,7 @@ func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops in
294303
if err != nil {
295304
return future.fail(conn, err)
296305
}
306+
//nolint: errcheck
297307
return future.send(conn, func(enc *msgpack.Encoder) error {
298308
enc.EncodeMapLen(3)
299309
enc.EncodeUint64(KeySpaceNo)
@@ -309,6 +319,7 @@ func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops in
309319

310320
// CallAsync sends a call to registered tarantool function and returns Future.
311321
// It uses request code for tarantool 1.6, so future's result is always array of arrays
322+
//nolint: errcheck
312323
func (conn *Connection) CallAsync(functionName string, args interface{}) *Future {
313324
future := conn.newFuture(CallRequest)
314325
return future.send(conn, func(enc *msgpack.Encoder) error {
@@ -325,6 +336,7 @@ func (conn *Connection) CallAsync(functionName string, args interface{}) *Future
325336
// (though, keep in mind, result is always array)
326337
func (conn *Connection) Call17Async(functionName string, args interface{}) *Future {
327338
future := conn.newFuture(Call17Request)
339+
//nolint: errcheck
328340
return future.send(conn, func(enc *msgpack.Encoder) error {
329341
enc.EncodeMapLen(2)
330342
enc.EncodeUint64(KeyFunctionName)
@@ -337,6 +349,7 @@ func (conn *Connection) Call17Async(functionName string, args interface{}) *Futu
337349
// EvalAsync sends a lua expression for evaluation and returns Future.
338350
func (conn *Connection) EvalAsync(expr string, args interface{}) *Future {
339351
future := conn.newFuture(EvalRequest)
352+
//nolint: errcheck
340353
return future.send(conn, func(enc *msgpack.Encoder) error {
341354
enc.EncodeMapLen(2)
342355
enc.EncodeUint64(KeyExpression)
@@ -350,6 +363,7 @@ func (conn *Connection) EvalAsync(expr string, args interface{}) *Future {
350363
// private
351364
//
352365

366+
//nolint: errcheck
353367
func (fut *Future) pack(h *smallWBuf, enc *msgpack.Encoder, body func(*msgpack.Encoder) error) (err error) {
354368
rid := fut.requestId
355369
hl := h.Len()

response.go

+3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ type Response struct {
1515
buf smallBuf
1616
}
1717

18+
//nolint: unused
1819
func (resp *Response) fill(b []byte) {
1920
resp.buf.b = b
2021
}
2122

23+
//nolint: errcheck
2224
func (resp *Response) smallInt(d *msgpack.Decoder) (i int, err error) {
2325
b, err := resp.buf.ReadByte()
2426
if err != nil {
@@ -31,6 +33,7 @@ func (resp *Response) smallInt(d *msgpack.Decoder) (i int, err error) {
3133
return d.DecodeInt()
3234
}
3335

36+
//nolint: errcheck
3437
func (resp *Response) decodeHeader(d *msgpack.Decoder) (err error) {
3538
var l int
3639
d.Reset(&resp.buf)

schema.go

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type IndexField struct {
4949
Type string
5050
}
5151

52+
//nolint: varcheck,deadcode
5253
const (
5354
maxSchemas = 10000
5455
spaceSpId = 280

0 commit comments

Comments
 (0)