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

Make "WriteConcern" struct parameterized to accept either int or string for W

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: Read and Write Concern
    • None
    • 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?

      When GODRIVER-2685 is complete, the W field in the writeconcern.WriteConcern struct will be exported and visible/settable by anyone. While that simplifies the writeconcern package API, the field can be either a string or an int, so it has to be type interface{}, which can be confusing to users because it doesn't specify what type is required (any value can be set, but some values will result in BSON marshal errors).

      For Go Driver 2.0, we can use generics, so make WriteConcern parameterized so we can limit the types usable for W to int or string.

      E.g.

      type WriteConcern[T string | int] struct {
      	W T
      	// ...
      

      Definition of done:

      • The W field on a WriteConcern can only be a string or an int.

      Note that users will have to update any WriteConcern literal declarations to include the type parameter. E.g.

      &writeconcern.WriteConcern[int]{W: 2}
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            matt.dale@mongodb.com Matt Dale
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: