-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
-
Major Change
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".
- has to be done after
-
GODRIVER-2696 Use an options pattern that doesn't require merging structs
- Closed
- is depended on by
-
GODRIVER-2696 Use an options pattern that doesn't require merging structs
- Closed
- is related to
-
GODRIVER-964 make option type construction consistent with the options package (e.g. readpref, readconcern, writeconcern)
- Closed