Skip to content

Commit f5dbf5b

Browse files
committed
fix: time.Since should not be used in defer statement
This commit fixes the complaining from `go vet` about the deferring of `time.Since`. This can cause wrong time evaluation of the elapsed time. This impact only the debug level, but still it should be addressed. ref: golang/go#60048 Signed-off-by: Maurizio Del Corno <[email protected]>
1 parent c0b6e01 commit f5dbf5b

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

pkg/client/client.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ func (c *immuClient) CurrentState(ctx context.Context) (*schema.ImmutableState,
994994
}
995995

996996
start := time.Now()
997-
defer c.Logger.Debugf("Current state finished in %s", time.Since(start))
997+
defer func() { c.Logger.Debugf("Current state finished in %s", time.Since(start)) }()
998998

999999
return c.ServiceClient.CurrentState(ctx, &empty.Empty{})
10001000
}
@@ -1006,7 +1006,7 @@ func (c *immuClient) Get(ctx context.Context, key []byte, opts ...GetOption) (*s
10061006
}
10071007

10081008
start := time.Now()
1009-
defer c.Logger.Debugf("get finished in %s", time.Since(start))
1009+
defer func() { c.Logger.Debugf("get finished in %s", time.Since(start)) }()
10101010

10111011
req := &schema.KeyRequest{Key: key}
10121012
for _, opt := range opts {
@@ -1040,7 +1040,7 @@ func (c *immuClient) GetAtRevision(ctx context.Context, key []byte, rev int64) (
10401040
// Gets reads a single value for given key with additional server-provided proof validation.
10411041
func (c *immuClient) VerifiedGet(ctx context.Context, key []byte, opts ...GetOption) (vi *schema.Entry, err error) {
10421042
start := time.Now()
1043-
defer c.Logger.Debugf("VerifiedGet finished in %s", time.Since(start))
1043+
defer func() { c.Logger.Debugf("VerifiedGet finished in %s", time.Since(start)) }()
10441044

10451045
req := &schema.KeyRequest{Key: key}
10461046
for _, opt := range opts {
@@ -1307,7 +1307,7 @@ func (c *immuClient) VerifiedSet(ctx context.Context, key []byte, value []byte)
13071307
}
13081308

13091309
start := time.Now()
1310-
defer c.Logger.Debugf("VerifiedSet finished in %s", time.Since(start))
1310+
defer func() { c.Logger.Debugf("VerifiedSet finished in %s", time.Since(start)) }()
13111311

13121312
state, err := c.StateService.GetState(ctx, c.Options.CurrentDatabase)
13131313
if err != nil {
@@ -1467,7 +1467,7 @@ func (c *immuClient) GetAll(ctx context.Context, keys [][]byte) (*schema.Entries
14671467
}
14681468

14691469
start := time.Now()
1470-
defer c.Logger.Debugf("get-batch finished in %s", time.Since(start))
1470+
defer func() { c.Logger.Debugf("get-batch finished in %s", time.Since(start)) }()
14711471

14721472
keyList := &schema.KeyListRequest{}
14731473

@@ -1495,12 +1495,11 @@ func (c *immuClient) TxByID(ctx context.Context, tx uint64) (*schema.Tx, error)
14951495
}
14961496

14971497
start := time.Now()
1498-
defer c.Logger.Debugf("by-index finished in %s", time.Since(start))
1498+
defer func() { c.Logger.Debugf("by-index finished in %s", time.Since(start)) }()
14991499

15001500
t, err := c.ServiceClient.TxById(ctx, &schema.TxRequest{
15011501
Tx: tx,
15021502
})
1503-
15041503
if err != nil {
15051504
return nil, err
15061505
}
@@ -1533,7 +1532,7 @@ func (c *immuClient) VerifiedTxByID(ctx context.Context, tx uint64) (*schema.Tx,
15331532
}
15341533

15351534
start := time.Now()
1536-
defer c.Logger.Debugf("VerifiedTxByID finished in %s", time.Since(start))
1535+
defer func() { c.Logger.Debugf("VerifiedTxByID finished in %s", time.Since(start)) }()
15371536

15381537
state, err := c.StateService.GetState(ctx, c.Options.CurrentDatabase)
15391538
if err != nil {
@@ -1619,7 +1618,7 @@ func (c *immuClient) History(ctx context.Context, req *schema.HistoryRequest) (s
16191618
}
16201619

16211620
start := time.Now()
1622-
defer c.Logger.Debugf("history finished in %s", time.Since(start))
1621+
defer func() { c.Logger.Debugf("history finished in %s", time.Since(start)) }()
16231622

16241623
return c.ServiceClient.History(ctx, req)
16251624
}
@@ -1640,7 +1639,7 @@ func (c *immuClient) SetReferenceAt(ctx context.Context, key []byte, referencedK
16401639
}
16411640

16421641
start := time.Now()
1643-
defer c.Logger.Debugf("SetReference finished in %s", time.Since(start))
1642+
defer func() { c.Logger.Debugf("SetReference finished in %s", time.Since(start)) }()
16441643

16451644
txhdr, err := c.ServiceClient.SetReference(ctx, &schema.ReferenceRequest{
16461645
Key: key,
@@ -1683,7 +1682,7 @@ func (c *immuClient) VerifiedSetReferenceAt(ctx context.Context, key []byte, ref
16831682
}
16841683

16851684
start := time.Now()
1686-
defer c.Logger.Debugf("safereference finished in %s", time.Since(start))
1685+
defer func() { c.Logger.Debugf("safereference finished in %s", time.Since(start)) }()
16871686

16881687
state, err := c.StateService.GetState(ctx, c.Options.CurrentDatabase)
16891688
if err != nil {
@@ -1798,7 +1797,7 @@ func (c *immuClient) ZAddAt(ctx context.Context, set []byte, score float64, key
17981797
}
17991798

18001799
start := time.Now()
1801-
defer c.Logger.Debugf("zadd finished in %s", time.Since(start))
1800+
defer func() { c.Logger.Debugf("zadd finished in %s", time.Since(start)) }()
18021801

18031802
hdr, err := c.ServiceClient.ZAdd(ctx, &schema.ZAddRequest{
18041803
Set: set,
@@ -1848,7 +1847,7 @@ func (c *immuClient) VerifiedZAddAt(ctx context.Context, set []byte, score float
18481847
}
18491848

18501849
start := time.Now()
1851-
defer c.Logger.Debugf("safezadd finished in %s", time.Since(start))
1850+
defer func() { c.Logger.Debugf("safezadd finished in %s", time.Since(start)) }()
18521851

18531852
state, err := c.StateService.GetState(ctx, c.Options.CurrentDatabase)
18541853
if err != nil {

pkg/client/streams.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (c *immuClient) _streamVerifiedSet(ctx context.Context, kvs []*stream.KeyVa
141141
defer c.StateService.CacheUnlock()
142142

143143
start := time.Now()
144-
defer c.Logger.Debugf("StreamVerifiedSet finished in %s", time.Since(start))
144+
defer func() { c.Logger.Debugf("StreamVerifiedSet finished in %s", time.Since(start)) }()
145145

146146
state, err := c.StateService.GetState(ctx, c.Options.CurrentDatabase)
147147
if err != nil {

0 commit comments

Comments
 (0)