You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

runcmdoptions.go 1.2 kB

5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940
  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. package options
  7. import "go.mongodb.org/mongo-driver/mongo/readpref"
  8. // RunCmdOptions represents all possible options for a runCommand operation.
  9. type RunCmdOptions struct {
  10. ReadPreference *readpref.ReadPref // The read preference for the operation.
  11. }
  12. // RunCmd creates a new *RunCmdOptions
  13. func RunCmd() *RunCmdOptions {
  14. return &RunCmdOptions{}
  15. }
  16. // SetReadPreference sets the read preference for the operation.
  17. func (rc *RunCmdOptions) SetReadPreference(rp *readpref.ReadPref) *RunCmdOptions {
  18. rc.ReadPreference = rp
  19. return rc
  20. }
  21. // MergeRunCmdOptions combines the given *RunCmdOptions into one *RunCmdOptions in a last one wins fashion.
  22. func MergeRunCmdOptions(opts ...*RunCmdOptions) *RunCmdOptions {
  23. rc := RunCmd()
  24. for _, opt := range opts {
  25. if opt == nil {
  26. continue
  27. }
  28. if opt.ReadPreference != nil {
  29. rc.ReadPreference = opt.ReadPreference
  30. }
  31. }
  32. return rc
  33. }