[GODRIVER-2689] Simplify the "readpref" API Created: 12/Dec/22  Updated: 08/Jan/24

Status: Backlog
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 2.0.0

Type: Improvement Priority: Unknown
Reporter: Matt Dale Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by GODRIVER-2696 Allow only 0 or 1 options structs in ... Investigating
Related
is related to GODRIVER-964 make option type construction consist... Closed
Epic Link: Go Driver 2.0: Driver
Backwards Compatibility: Major Change
Documentation Changes Summary:

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?


 Description   

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.


 Comments   
Comment by Githook User [ 27/Apr/23 ]

Author:

{'name': 'Matt Dale', 'email': '9760375+matthewdale@users.noreply.github.com', 'username': 'matthewdale'}

Message: GODRIVER-2689 Always return a distinct Primary read preference. (#1233)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/741b0ed7a2e8ff15e53fa3a98d25f49a0279bfe9

Comment by Matt Dale [ 18/Apr/23 ]

It's not possible to do this ahead of Go Driver 2.0 because there are too many name collisions. Moving this to the Go Driver 2.0 epic.

Generated at Thu Feb 08 08:39:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.