Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2689

Simplify the "readpref" API

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • 3.0.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Major Change
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      The readpref package and types use a lot of unnecessary APIs that can confuse users. We should remove the functional options pattern and just export all fields in the ReadPref struct so users can set them directly. Any field that has a corresponding "Set" field to indicate whether the value was set or not should be an exported pointer value instead (e.g. maxStaleness time.Duration and maxStalenessSet bool should be replaced with MaxStaleness *time.Duration).

      Also, some exported values or functions do not need to be exported:

      • ErrInvalidTagSet - Unless users are dynamically building read preferences at run time, these error are unrecoverable and do not need to support special conditional logic (e.g. if err == ErrInvalidTagSet).

      Definition of done:

      • Export all fields in the ReadPref struct.
        • Do not export maxStalenessSet, but change type of MaxStaleness to *time.Duration instead.
      • Remove Option type and all Option functions.
      • Update the readpref.Primary shortcut function to create a new ReadPref on each call since users can modify the returned struct.
      • Remove Mode.IsValid, which has a single use case in the Go driver, which can be replaced by a switch condition in that one place.
      • Remove or unexport all exported error values.
      • (Optional) Consider merging the tag package into the readpref package because "tags" are always "read preference tags".

            Assignee:
            preston.vasquez@mongodb.com Preston Vasquez
            Reporter:
            matt.dale@mongodb.com Matt Dale
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: