Skip to content

Commit a21c36b

Browse files
authored
GODRIVER-2156 Enable makezero linter. (#801)
1 parent 5e714b3 commit a21c36b

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ linters:
1212
- gosimple
1313
- govet
1414
- ineffassign
15+
- makezero
1516
# - misspell
1617
- nakedret
1718
- revive

mongo/collection.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,9 +1274,9 @@ func (coll *Collection) FindOne(ctx context.Context, filter interface{},
12741274
ctx = context.Background()
12751275
}
12761276

1277-
findOpts := make([]*options.FindOptions, len(opts))
1278-
for i, opt := range opts {
1279-
findOpts[i] = &options.FindOptions{
1277+
findOpts := make([]*options.FindOptions, 0, len(opts))
1278+
for _, opt := range opts {
1279+
findOpts = append(findOpts, &options.FindOptions{
12801280
AllowPartialResults: opt.AllowPartialResults,
12811281
BatchSize: opt.BatchSize,
12821282
Collation: opt.Collation,
@@ -1295,7 +1295,7 @@ func (coll *Collection) FindOne(ctx context.Context, filter interface{},
12951295
Skip: opt.Skip,
12961296
Snapshot: opt.Snapshot,
12971297
Sort: opt.Sort,
1298-
}
1298+
})
12991299
}
13001300
// Unconditionally send a limit to make sure only one document is returned and the cursor is not kept open
13011301
// by the server.

x/mongo/driver/topology/server.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ func NewServer(addr address.Address, topologyID primitive.ObjectID, opts ...Serv
180180
PoolMonitor: cfg.poolMonitor,
181181
}
182182

183-
connectionOpts := make([]ConnectionOption, len(cfg.connectionOpts))
184-
copy(connectionOpts, cfg.connectionOpts)
183+
connectionOpts := copyConnectionOpts(cfg.connectionOpts)
185184
connectionOpts = append(connectionOpts, withErrorHandlingCallback(s.ProcessHandshakeError))
186185
s.pool = newPool(pc, connectionOpts...)
187186
s.publishServerOpeningEvent(s.address)
@@ -590,8 +589,7 @@ func (s *Server) updateDescription(desc description.Server) {
590589
// createConnection creates a new connection instance but does not call connect on it. The caller must call connect
591590
// before the connection can be used for network operations.
592591
func (s *Server) createConnection() (*connection, error) {
593-
opts := make([]ConnectionOption, len(s.cfg.connectionOpts))
594-
copy(opts, s.cfg.connectionOpts)
592+
opts := copyConnectionOpts(s.cfg.connectionOpts)
595593
opts = append(opts,
596594
WithConnectTimeout(func(time.Duration) time.Duration { return s.cfg.heartbeatTimeout }),
597595
WithReadTimeout(func(time.Duration) time.Duration { return s.cfg.heartbeatTimeout }),
@@ -609,6 +607,12 @@ func (s *Server) createConnection() (*connection, error) {
609607
return newConnection(s.address, opts...)
610608
}
611609

610+
func copyConnectionOpts(opts []ConnectionOption) []ConnectionOption {
611+
optsCopy := make([]ConnectionOption, len(opts))
612+
copy(optsCopy, opts)
613+
return optsCopy
614+
}
615+
612616
func (s *Server) setupHeartbeatConnection() error {
613617
conn, err := s.createConnection()
614618
if err != nil {

0 commit comments

Comments
 (0)