Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GODRIVER-2156 Enable makezero linter. #801

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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