-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLOUDP-237245: adding helper for using Http transport interface #35
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -124,6 +124,16 @@ func NewTransportWithHTTPTransport(username, password string, transport *http.Tr | |||
return t | |||
} | |||
|
|||
// NewTransportWithHTTPRoundTripper creates a new digest transport using the supplied http.RoundTripper interface. | |||
func NewTransportWithHTTPRoundTripper(username, password string, transport http.RoundTripper) *Transport { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the prefix New
a common convention?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes there are no constructors in go so this is the convention for constructor like behavior, also there's no method overloading so the With
is somewhat common as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I didn't mention this on the code review since NewTransportWithHTTPTransport
already exists but both NewTransportWithHTTPTransport
and the new method are not necessary can already create a new transport doing
t := &digest.Transport{
Username: username,
Password: password,
Transport: transport,
}
or even
t := &digest.Transport{
username,
password,
transport,
}
New
methods are only needed if there are private fields or added logic but Transport
has none
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My personal opinion is that New methods produce slightly better end user API as new fields in the structure would not cause compilation issues.
Example:
mongodb/atlas-sdk-go@0f2d20a
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/mongodb-forks/digest](https://togithub.com/mongodb-forks/digest) | `v1.0.5` -> `v1.1.0` | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | [](https://docs.renovatebot.com/merge-confidence/) | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>mongodb-forks/digest (github.com/mongodb-forks/digest)</summary> ### [`v1.1.0`](https://togithub.com/mongodb-forks/digest/releases/tag/v1.1.0) [Compare Source](https://togithub.com/mongodb-forks/digest/compare/v1.0.5...v1.1.0) #### What's Changed - build(deps): bump actions/checkout from 3 to 4 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/mongodb-forks/digest/pull/30](https://togithub.com/mongodb-forks/digest/pull/30) - build(deps): bump golangci/golangci-lint-action from 3.7.0 to 4.0.0 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/mongodb-forks/digest/pull/31](https://togithub.com/mongodb-forks/digest/pull/31) - build(deps): bump actions/cache from 3 to 4 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/mongodb-forks/digest/pull/32](https://togithub.com/mongodb-forks/digest/pull/32) - build(deps): bump actions/setup-go from 4 to 5 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/mongodb-forks/digest/pull/33](https://togithub.com/mongodb-forks/digest/pull/33) - task: update go matrix by [@​gssbzn](https://togithub.com/gssbzn) in [https://github.com/mongodb-forks/digest/pull/34](https://togithub.com/mongodb-forks/digest/pull/34) - CLOUDP-237245: adding helper for using Http transport interface by [@​wtrocki](https://togithub.com/wtrocki) in [https://github.com/mongodb-forks/digest/pull/35](https://togithub.com/mongodb-forks/digest/pull/35) **Full Changelog**: mongodb-forks/digest@v1.0.5...v1.1.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - "on tuesday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/open-telemetry/opentelemetry-collector-contrib). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNjkuMiIsInVwZGF0ZWRJblZlciI6IjM3LjI2OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: opentelemetrybot <107717825+opentelemetrybot@users.noreply.github.com>
Context
Current digest library uses
transport *http.Transport
as interface for creating new transport.However the generic http interface relies on
http.RoundTripper
pointer interface.Change
Adding helper to support interoperability with libraries that confirm with
http.RoundTripper
.Notes
Left previous version of the method to not cause unneeded breaking changes. Both use cases are correct and valid.