Skip to content

Commit

Permalink
GODRIVER-2156 Enable makezero linter. (mongodb#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewdale authored and Mohammad Fahim Abrar committed Mar 17, 2022
1 parent 0434b52 commit 8d5b798
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ linters:
- gosimple
- govet
- ineffassign
- makezero
# - misspell
- nakedret
- revive
Expand Down
8 changes: 4 additions & 4 deletions mongo/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1274,9 +1274,9 @@ func (coll *Collection) FindOne(ctx context.Context, filter interface{},
ctx = context.Background()
}

findOpts := make([]*options.FindOptions, len(opts))
for i, opt := range opts {
findOpts[i] = &options.FindOptions{
findOpts := make([]*options.FindOptions, 0, len(opts))
for _, opt := range opts {
findOpts = append(findOpts, &options.FindOptions{
AllowPartialResults: opt.AllowPartialResults,
BatchSize: opt.BatchSize,
Collation: opt.Collation,
Expand All @@ -1295,7 +1295,7 @@ func (coll *Collection) FindOne(ctx context.Context, filter interface{},
Skip: opt.Skip,
Snapshot: opt.Snapshot,
Sort: opt.Sort,
}
})
}
// Unconditionally send a limit to make sure only one document is returned and the cursor is not kept open
// by the server.
Expand Down
12 changes: 8 additions & 4 deletions x/mongo/driver/topology/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ func NewServer(addr address.Address, topologyID primitive.ObjectID, opts ...Serv
PoolMonitor: cfg.poolMonitor,
}

connectionOpts := make([]ConnectionOption, len(cfg.connectionOpts))
copy(connectionOpts, cfg.connectionOpts)
connectionOpts := copyConnectionOpts(cfg.connectionOpts)
connectionOpts = append(connectionOpts, withErrorHandlingCallback(s.ProcessHandshakeError))
s.pool = newPool(pc, connectionOpts...)
s.publishServerOpeningEvent(s.address)
Expand Down Expand Up @@ -590,8 +589,7 @@ func (s *Server) updateDescription(desc description.Server) {
// createConnection creates a new connection instance but does not call connect on it. The caller must call connect
// before the connection can be used for network operations.
func (s *Server) createConnection() (*connection, error) {
opts := make([]ConnectionOption, len(s.cfg.connectionOpts))
copy(opts, s.cfg.connectionOpts)
opts := copyConnectionOpts(s.cfg.connectionOpts)
opts = append(opts,
WithConnectTimeout(func(time.Duration) time.Duration { return s.cfg.heartbeatTimeout }),
WithReadTimeout(func(time.Duration) time.Duration { return s.cfg.heartbeatTimeout }),
Expand All @@ -609,6 +607,12 @@ func (s *Server) createConnection() (*connection, error) {
return newConnection(s.address, opts...)
}

func copyConnectionOpts(opts []ConnectionOption) []ConnectionOption {
optsCopy := make([]ConnectionOption, len(opts))
copy(optsCopy, opts)
return optsCopy
}

func (s *Server) setupHeartbeatConnection() error {
conn, err := s.createConnection()
if err != nil {
Expand Down

0 comments on commit 8d5b798

Please sign in to comment.