blob: c7c696de9836133c818a31712714bd28ba7cc90e [file] [log] [blame]
Don Newton379ae252019-04-01 12:17:06 -04001// Copyright (C) MongoDB, Inc. 2017-present.
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may
4// not use this file except in compliance with the License. You may obtain
5// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
7package options
8
9import "github.com/mongodb/mongo-go-driver/mongo/readpref"
10
11// RunCmdOptions represents all possible options for a runCommand operation.
12type RunCmdOptions struct {
13 ReadPreference *readpref.ReadPref // The read preference for the operation.
14}
15
16// RunCmd creates a new *RunCmdOptions
17func RunCmd() *RunCmdOptions {
18 return &RunCmdOptions{}
19}
20
21// SetReadPreference sets the read preference for the operation.
22func (rc *RunCmdOptions) SetReadPreference(rp *readpref.ReadPref) *RunCmdOptions {
23 rc.ReadPreference = rp
24 return rc
25}
26
27// MergeRunCmdOptions combines the given *RunCmdOptions into one *RunCmdOptions in a last one wins fashion.
28func MergeRunCmdOptions(opts ...*RunCmdOptions) *RunCmdOptions {
29 rc := RunCmd()
30 for _, opt := range opts {
31 if opt == nil {
32 continue
33 }
34 if opt.ReadPreference != nil {
35 rc.ReadPreference = opt.ReadPreference
36 }
37 }
38
39 return rc
40}