Don Newton | 379ae25 | 2019-04-01 12:17:06 -0400 | [diff] [blame^] | 1 | // 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 | |
| 7 | package options |
| 8 | |
| 9 | import "github.com/mongodb/mongo-go-driver/mongo/readpref" |
| 10 | |
| 11 | // RunCmdOptions represents all possible options for a runCommand operation. |
| 12 | type RunCmdOptions struct { |
| 13 | ReadPreference *readpref.ReadPref // The read preference for the operation. |
| 14 | } |
| 15 | |
| 16 | // RunCmd creates a new *RunCmdOptions |
| 17 | func RunCmd() *RunCmdOptions { |
| 18 | return &RunCmdOptions{} |
| 19 | } |
| 20 | |
| 21 | // SetReadPreference sets the read preference for the operation. |
| 22 | func (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. |
| 28 | func 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 | } |