mongodb / go-client-mongodb-atlas

Go Client for MongoDB Atlas
https://www.mongodb.com/docs/atlas/reference/api-resources-spec/
Apache License 2.0
79 stars 34 forks source link

Enable fluent and struct API for go SDK #464

Closed wtrocki closed 1 year ago

wtrocki commented 1 year ago

One of the biggest problems integrations might face is that fluent API forces end users to use specific interface (chain of operations/builder pattern-like) solutions. In many cases, this will mean that migration between SDKv1 and SDKv2 will be quite painful.

This PR introduces a new method to the API object that can accept structs.

As result, users will get:

While this change might look big due to the number of files changed what we changing here is only a single template that adds a new method. I will be looking to adopt this upstream as well. Change is not breaking - it doesn't affect any goals and existing documentation etc.

Notes about recent updates

  1. I have made this feature experimental for now. Fluent API is still the default feature
  2. I will focus on small breaking changes for fluent API in separate PR to simplify the review. This PR contains all non-breaking changes for atlas CLI (tested end to end)
wtrocki commented 1 year ago

As an outstanding item, we might need to clarify what to do with not optional arguments (Those are now supplied to method that creates requests and cannot be avoided. I really wanted to avoid breaking change for fluent API

wtrocki commented 1 year ago

The biggest challenge/inconvenience of that approach is that we need to supply a struct to the API containing nonoptional fields that we already supplied, making it a bad api. We can eventually generate a separate struct for that purpose.

wtrocki commented 1 year ago

Putting that PR on hold for now

gssbzn commented 1 year ago

waiting on https://github.com/mongodb/go-client-mongodb-atlas/pull/464#discussion_r1188312909