options.go 759 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package mon
  2. import (
  3. "time"
  4. "github.com/zeromicro/go-zero/core/syncx"
  5. mopt "go.mongodb.org/mongo-driver/mongo/options"
  6. )
  7. const defaultTimeout = time.Second * 3
  8. var slowThreshold = syncx.ForAtomicDuration(defaultSlowThreshold)
  9. type (
  10. options = mopt.ClientOptions
  11. // Option defines the method to customize a mongo model.
  12. Option func(opts *options)
  13. )
  14. // SetSlowThreshold sets the slow threshold.
  15. func SetSlowThreshold(threshold time.Duration) {
  16. slowThreshold.Set(threshold)
  17. }
  18. func defaultTimeoutOption() Option {
  19. return func(opts *options) {
  20. opts.SetTimeout(defaultTimeout)
  21. }
  22. }
  23. // WithTimeout set the mon client operation timeout.
  24. func WithTimeout(timeout time.Duration) Option {
  25. return func(opts *options) {
  26. opts.SetTimeout(timeout)
  27. }
  28. }