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 ( 10 "go.mongodb.org/mongo-driver/mongo/readpref" 11 ) 12 13 // RunCmdOptions represents options that can be used to configure a RunCommand operation. 14 type RunCmdOptions struct { 15 // The read preference to use for the operation. The default value is nil, which means that the primary read 16 // preference will be used. 17 ReadPreference *readpref.ReadPref 18 } 19 20 // RunCmd creates a new RunCmdOptions instance. 21 func RunCmd() *RunCmdOptions { 22 return &RunCmdOptions{} 23 } 24 25 // SetReadPreference sets value for the ReadPreference field. 26 func (rc *RunCmdOptions) SetReadPreference(rp *readpref.ReadPref) *RunCmdOptions { 27 rc.ReadPreference = rp 28 return rc 29 } 30 31 // MergeRunCmdOptions combines the given RunCmdOptions instances into one *RunCmdOptions in a last-one-wins fashion. 32 // 33 // Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a 34 // single options struct instead. 35 func MergeRunCmdOptions(opts ...*RunCmdOptions) *RunCmdOptions { 36 rc := RunCmd() 37 for _, opt := range opts { 38 if opt == nil { 39 continue 40 } 41 if opt.ReadPreference != nil { 42 rc.ReadPreference = opt.ReadPreference 43 } 44 } 45 46 return rc 47 } 48