Skip to content

Commit 943a049

Browse files
committed
Fix linters complaints
1 parent 6f1e772 commit 943a049

24 files changed

+544
-172
lines changed

cluster_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,14 @@ func TestNewCluster_Defaults(t *testing.T) {
4646
assertEqual(t, "cluster config reconnect interval", 60*time.Second, cfg.ReconnectInterval)
4747
assertTrue(t, "cluster config conviction policy",
4848
reflect.DeepEqual(&SimpleConvictionPolicy{}, cfg.ConvictionPolicy))
49-
assertTrue(t, "cluster config reconnection policy",
50-
reflect.DeepEqual(&ConstantReconnectionPolicy{MaxRetries: 3, Interval: 1 * time.Second}, cfg.ReconnectionPolicy))
49+
assertTrue(
50+
t,
51+
"cluster config reconnection policy",
52+
reflect.DeepEqual(
53+
&ConstantReconnectionPolicy{MaxRetries: 3, Interval: 1 * time.Second},
54+
cfg.ReconnectionPolicy,
55+
),
56+
)
5157
}
5258

5359
func TestNewCluster_WithHosts(t *testing.T) {

common_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ import (
4040
)
4141

4242
var (
43-
flagCluster = flag.String("cluster", "127.0.0.1", "a comma-separated list of host:port tuples")
44-
flagProto = flag.Int("proto", 0, "protcol version")
45-
flagCQL = flag.String("cql", "3.0.0", "CQL version")
46-
flagRF = flag.Int("rf", 1, "replication factor for test keyspace")
47-
clusterSize = flag.Int("clusterSize", 1, "the expected size of the cluster")
48-
flagRetry = flag.Int("retries", 5, "number of times to retry queries")
49-
flagAutoWait = flag.Duration("autowait", 1000*time.Millisecond, "time to wait for autodiscovery to fill the hosts poll")
43+
flagCluster = flag.String("cluster", "127.0.0.1", "a comma-separated list of host:port tuples")
44+
flagProto = flag.Int("proto", 0, "protcol version")
45+
flagCQL = flag.String("cql", "3.0.0", "CQL version")
46+
flagRF = flag.Int("rf", 1, "replication factor for test keyspace")
47+
clusterSize = flag.Int("clusterSize", 1, "the expected size of the cluster")
48+
flagRetry = flag.Int("retries", 5, "number of times to retry queries")
49+
flagAutoWait = flag.Duration(
50+
"autowait",
51+
1000*time.Millisecond,
52+
"time to wait for autodiscovery to fill the hosts poll",
53+
)
5054
flagRunSslTest = flag.Bool("runssl", false, "Set to true to run ssl test")
5155
flagRunAuthTest = flag.Bool("runauth", false, "Set to true to run authentication test")
5256
flagCompressTest = flag.String("compressor", "no-compression", "compressor to use")

conn.go

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,12 @@ func (s *Session) connect(ctx context.Context, host *HostInfo, errorHandler Conn
217217
}
218218

219219
// dial establishes a connection to a Cassandra node and notifies the session's connectObserver.
220-
func (s *Session) dial(ctx context.Context, host *HostInfo, connConfig *ConnConfig, errorHandler ConnErrorHandler) (*Conn, error) {
220+
func (s *Session) dial(
221+
ctx context.Context,
222+
host *HostInfo,
223+
connConfig *ConnConfig,
224+
errorHandler ConnErrorHandler,
225+
) (*Conn, error) {
221226
var obs ObservedConnect
222227
if s.connectObserver != nil {
223228
obs.Host = host
@@ -238,7 +243,12 @@ func (s *Session) dial(ctx context.Context, host *HostInfo, connConfig *ConnConf
238243
// dialWithoutObserver establishes connection to a Cassandra node.
239244
//
240245
// dialWithoutObserver does not notify the connection observer, so you most probably want to call dial() instead.
241-
func (s *Session) dialWithoutObserver(ctx context.Context, host *HostInfo, cfg *ConnConfig, errorHandler ConnErrorHandler) (*Conn, error) {
246+
func (s *Session) dialWithoutObserver(
247+
ctx context.Context,
248+
host *HostInfo,
249+
cfg *ConnConfig,
250+
errorHandler ConnErrorHandler,
251+
) (*Conn, error) {
242252
dialedHost, err := cfg.HostDialer.DialHost(ctx, host)
243253
if err != nil {
244254
return nil, err
@@ -385,7 +395,11 @@ func (s *startupCoordinator) setupConn(ctx context.Context) error {
385395
return nil
386396
}
387397

388-
func (s *startupCoordinator) write(ctx context.Context, frame frameBuilder, startupCompleted *atomic.Bool) (frame, error) {
398+
func (s *startupCoordinator) write(
399+
ctx context.Context,
400+
frame frameBuilder,
401+
startupCompleted *atomic.Bool,
402+
) (frame, error) {
389403
select {
390404
case s.frameTicker <- struct{}{}:
391405
case <-ctx.Done():
@@ -414,7 +428,11 @@ func (s *startupCoordinator) options(ctx context.Context, startupCompleted *atom
414428
return s.startup(ctx, supported.supported, startupCompleted)
415429
}
416430

417-
func (s *startupCoordinator) startup(ctx context.Context, supported map[string][]string, startupCompleted *atomic.Bool) error {
431+
func (s *startupCoordinator) startup(
432+
ctx context.Context,
433+
supported map[string][]string,
434+
startupCompleted *atomic.Bool,
435+
) error {
418436
m := map[string]string{
419437
"CQL_VERSION": s.conn.cfg.CQLVersion,
420438
"DRIVER_NAME": driverName,
@@ -457,7 +475,11 @@ func (s *startupCoordinator) startup(ctx context.Context, supported map[string][
457475
}
458476
}
459477

460-
func (s *startupCoordinator) authenticateHandshake(ctx context.Context, authFrame *authenticateFrame, startupCompleted *atomic.Bool) error {
478+
func (s *startupCoordinator) authenticateHandshake(
479+
ctx context.Context,
480+
authFrame *authenticateFrame,
481+
startupCompleted *atomic.Bool,
482+
) error {
461483
if s.conn.auth == nil {
462484
return fmt.Errorf("authentication required (using %q)", authFrame.class)
463485
}
@@ -592,7 +614,7 @@ func (c *Conn) heartBeat(ctx context.Context) {
592614

593615
for {
594616
if failures > 5 {
595-
c.closeWithError(fmt.Errorf("gocql: heartbeat failed"))
617+
c.closeWithError(errors.New("gocql: heartbeat failed"))
596618
return
597619
}
598620

@@ -659,10 +681,10 @@ func (c *Conn) processFrame(ctx context.Context, r io.Reader) error {
659681

660682
if c.frameObserver != nil {
661683
c.frameObserver.ObserveFrameHeader(context.Background(), ObservedFrameHeader{
662-
Version: protoVersion(head.version),
684+
Version: head.version,
663685
Flags: head.flags,
664686
Stream: int16(head.stream),
665-
Opcode: frameOp(head.op),
687+
Opcode: head.op,
666688
Length: int32(head.length),
667689
Start: headStartTime,
668690
End: headEndTime,
@@ -822,7 +844,7 @@ func (c *Conn) recvPartialFrames(dst *bytes.Buffer, bytesToRead int) error {
822844
}
823845

824846
if isSelfContained {
825-
return fmt.Errorf("gocql: received self-contained segment, but expected not")
847+
return errors.New("gocql: received self-contained segment, but expected not")
826848
}
827849

828850
if totalLength := dst.Len() + len(frame); totalLength > dst.Cap() {
@@ -885,7 +907,7 @@ func (c *connReader) Read(p []byte) (n int, err error) {
885907
}
886908
}
887909

888-
return
910+
return n, err
889911
}
890912

891913
func (c *connReader) Write(b []byte) (n int, err error) {
@@ -1177,7 +1199,12 @@ func (c *Conn) exec(ctx context.Context, req frameBuilder, tracer Tracer) (*fram
11771199
return c.execInternal(ctx, req, tracer, true)
11781200
}
11791201

1180-
func (c *Conn) execInternal(ctx context.Context, req frameBuilder, tracer Tracer, startupCompleted bool) (*framer, error) {
1202+
func (c *Conn) execInternal(
1203+
ctx context.Context,
1204+
req frameBuilder,
1205+
tracer Tracer,
1206+
startupCompleted bool,
1207+
) (*framer, error) {
11811208
if ctxErr := ctx.Err(); ctxErr != nil {
11821209
return nil, ctxErr
11831210
}
@@ -1394,7 +1421,12 @@ type inflightPrepare struct {
13941421
preparedStatment *preparedStatment
13951422
}
13961423

1397-
func (c *Conn) prepareStatement(ctx context.Context, stmt string, tracer Tracer, keyspace string) (*preparedStatment, error) {
1424+
func (c *Conn) prepareStatement(
1425+
ctx context.Context,
1426+
stmt string,
1427+
tracer Tracer,
1428+
keyspace string,
1429+
) (*preparedStatment, error) {
13981430
stmtCacheKey := c.session.stmtsLRU.keyFor(c.host.HostID(), keyspace, stmt)
13991431
flight, ok := c.session.stmtsLRU.execIfMissing(stmtCacheKey, func(lru *lru.Cache) *inflightPrepare {
14001432
flight := &inflightPrepare{
@@ -1546,7 +1578,9 @@ func (c *Conn) executeQuery(ctx context.Context, qry *Query) *Iter {
15461578
}
15471579

15481580
if len(values) != info.request.actualColCount {
1549-
return &Iter{err: fmt.Errorf("gocql: expected %d values send got %d", info.request.actualColCount, len(values))}
1581+
return &Iter{
1582+
err: fmt.Errorf("gocql: expected %d values send got %d", info.request.actualColCount, len(values)),
1583+
}
15501584
}
15511585

15521586
params.values = make([]queryValues, len(values))
@@ -1560,7 +1594,8 @@ func (c *Conn) executeQuery(ctx context.Context, qry *Query) *Iter {
15601594
}
15611595

15621596
// if the metadata was not present in the response then we should not skip it
1563-
params.skipMeta = !(c.session.cfg.DisableSkipMetadata || qry.disableSkipMetadata) && info != nil && info.response.flags&flagNoMetaData == 0
1597+
params.skipMeta = !(c.session.cfg.DisableSkipMetadata || qry.disableSkipMetadata) && info != nil &&
1598+
info.response.flags&flagNoMetaData == 0
15641599

15651600
frame = &writeExecuteFrame{
15661601
preparedID: info.id,
@@ -1791,7 +1826,14 @@ func (c *Conn) executeBatch(ctx context.Context, batch *Batch) *Iter {
17911826
}
17921827

17931828
if len(values) != info.request.actualColCount {
1794-
return &Iter{err: fmt.Errorf("gocql: batch statement %d expected %d values send got %d", i, info.request.actualColCount, len(values))}
1829+
return &Iter{
1830+
err: fmt.Errorf(
1831+
"gocql: batch statement %d expected %d values send got %d",
1832+
i,
1833+
info.request.actualColCount,
1834+
len(values),
1835+
),
1836+
}
17951837
}
17961838

17971839
b.preparedID = info.id
@@ -1876,7 +1918,8 @@ func (c *Conn) querySystemPeers(ctx context.Context, version cassVersion) *Iter
18761918

18771919
err := iter.checkErrAndNotFound()
18781920
if err != nil {
1879-
if errFrame, ok := err.(errorFrame); ok && errFrame.code == ErrCodeInvalid { // system.peers_v2 not found, try system.peers
1921+
if errFrame, ok := err.(errorFrame); ok &&
1922+
errFrame.code == ErrCodeInvalid { // system.peers_v2 not found, try system.peers
18801923
c.mu.Lock()
18811924
c.isSchemaV2 = false
18821925
c.mu.Unlock()
@@ -1908,17 +1951,19 @@ func (c *Conn) awaitSchemaAgreement(ctx context.Context) (err error) {
19081951

19091952
versions = make(map[string]struct{})
19101953

1911-
rows, err := iter.SliceMap()
1954+
var rows []map[string]interface{}
1955+
rows, err = iter.SliceMap()
19121956
if err != nil {
19131957
goto cont
19141958
}
19151959

19161960
for _, row := range rows {
1917-
h, err := NewHostInfo(c.host.ConnectAddress(), c.session.cfg.Port)
1961+
var host *HostInfo
1962+
host, err = NewHostInfo(c.host.ConnectAddress(), c.session.cfg.Port)
19181963
if err != nil {
19191964
goto cont
19201965
}
1921-
host, err := c.session.hostInfoFromMap(row, h)
1966+
host, err = c.session.hostInfoFromMap(row, host)
19221967
if err != nil {
19231968
goto cont
19241969
}

connectionpool.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,14 @@ func (p *policyConnPool) getPool(host *HostInfo) (pool *hostConnPool, ok bool) {
240240
p.mu.RLock()
241241
pool, ok = p.hostConnPools[hostID]
242242
p.mu.RUnlock()
243-
return
243+
return pool, ok
244244
}
245245

246246
func (p *policyConnPool) getPoolByHostID(hostID string) (pool *hostConnPool, ok bool) {
247247
p.mu.RLock()
248248
pool, ok = p.hostConnPools[hostID]
249249
p.mu.RUnlock()
250-
return
250+
return pool, ok
251251
}
252252

253253
func (p *policyConnPool) Close() {
@@ -322,7 +322,6 @@ func (h *hostConnPool) String() string {
322322

323323
func newHostConnPool(session *Session, host *HostInfo, port, size int,
324324
keyspace string) *hostConnPool {
325-
326325
pool := &hostConnPool{
327326
session: session,
328327
host: host,

control.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ func parseProtocolFromError(err error) int {
213213
return 0
214214
}
215215

216-
max, err := strconv.Atoi(matches[0][1])
216+
val, err := strconv.Atoi(matches[0][1])
217217
if err != nil {
218218
return 0
219219
}
220220

221-
return max
221+
return val
222222
}
223223

224224
func (c *controlConn) discoverProtocol(hosts []*HostInfo) (int, error) {
@@ -272,7 +272,12 @@ func (c *controlConn) connect(hosts []*HostInfo) error {
272272
for _, host := range hosts {
273273
conn, err = c.session.dial(c.session.ctx, host, &cfg, c)
274274
if err != nil {
275-
c.session.logger.Printf("gocql: unable to dial control conn %v:%v: %v\n", host.ConnectAddress(), host.Port(), err)
275+
c.session.logger.Printf(
276+
"gocql: unable to dial control conn %v:%v: %v\n",
277+
host.ConnectAddress(),
278+
host.Port(),
279+
err,
280+
)
276281
continue
277282
}
278283
err = c.setupConn(conn)
@@ -434,7 +439,12 @@ func (c *controlConn) attemptReconnectToAnyOfHosts(hosts []*HostInfo) (*Conn, er
434439
for _, host := range hosts {
435440
conn, err = c.session.connect(c.session.ctx, host, c)
436441
if err != nil {
437-
c.session.logger.Printf("gocql: unable to dial control conn %v:%v: %v\n", host.ConnectAddress(), host.Port(), err)
442+
c.session.logger.Printf(
443+
"gocql: unable to dial control conn %v:%v: %v\n",
444+
host.ConnectAddress(),
445+
host.Port(),
446+
err,
447+
)
438448
continue
439449
}
440450
err = c.setupConn(conn)
@@ -532,7 +542,7 @@ func (c *controlConn) query(statement string, values ...interface{}) (iter *Iter
532542
}
533543
}
534544

535-
return
545+
return iter
536546
}
537547

538548
func (c *controlConn) awaitSchemaAgreement() error {

errors.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,12 @@ type RequestErrUnavailable struct {
148148
}
149149

150150
func (e *RequestErrUnavailable) String() string {
151-
return fmt.Sprintf("[request_error_unavailable consistency=%s required=%d alive=%d]", e.Consistency, e.Required, e.Alive)
151+
return fmt.Sprintf(
152+
"[request_error_unavailable consistency=%s required=%d alive=%d]",
153+
e.Consistency,
154+
e.Required,
155+
e.Alive,
156+
)
152157
}
153158

154159
type ErrorMap map[string]uint16

example_nulls_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ func Example_nulls() {
6565
} else {
6666
fmt.Printf("Row %d is null\n", id)
6767
}
68-
6968
}
7069
err = scanner.Err()
7170
if err != nil {

0 commit comments

Comments
 (0)