[WIP] minimal module awareness by joshuarubin · Pull Request #1963 · golang/dep (original) (raw)

brandur-stripe added a commit to stripe/stripe-go that referenced this pull request

Makes an API response struct containing niceties like the raw response body, status, and request ID accessible via API resource structs returned from client functions. For example:

customer, err := customer.New(params)
fmt.Printf("request ID = %s\n", customer.LastResponse.RequestID)

This is a feature that already exists in other language API libraries and which is requested occasionally here, usually for various situations involving more complex usage or desire for better observability.

-- Implementation

We introduce a few new types to make this work:

stripe.Do and other backend calls all start taking objects which are LastResponseGetter instead of interface{}. This provides us with some type safety around forgetting to include an embedded APIResource on structs that should have it by making the compiler balk.

As stripe.Do finishes running a request, it generates an APIResponse object and sets it onto the API resource type it's deserializing and returning (e.g. a Coupon).

Errors also embed APIResource and similarly get access to the same set of fields as response resources, although in their case some of the fields provided in APIResponse are duplicates of what they had already (see "Caveats" below).

-- Backwards compatibility

This is a minor breaking change in that backend implementations methods like Do now take LastResponseGetter instead of interface{}, which is more strict.

The good news though is that:

-- Naming

-- Caveats

Co-Authored-By: Olivier Bellone ob@stripe.com

Co-authored-by: Brandur brandur@stripe.com Co-authored-by: Olivier Bellone ob@stripe.com

Similar to the original implementation for Go Modules in #712, here we add a go.mod and go.sum, then proceed to use Go Modules style import paths everywhere that include the current major revision.

Unfortunately, this may still cause trouble for Dep users who are trying to upgrade stripe-go, but the project's now had two years to help its users with basic Go Module awareness, and has chosen not to do so. It's received no commits of any kind since August 2019, and therefore would be considered unmaintained by most definitions. Elsewhere, Go Modules now seem to be the only and obvious way forward, so we're likely to see more and more users on them.

scripts/check_api_clients/main.go is also updated to be smarter about breaking down package paths which may now include the major.

[1] golang/dep#1963

Move back down to current major version so that we can test that our release script will bump it to v71 properly when the time comes.

Co-authored-by: Brandur brandur@stripe.com Co-authored-by: Olivier Bellone ob@stripe.com Co-authored-by: Remi Jannel remi@stripe.com