Add Client.Clone function#774
Merged
jeevatkm merged 3 commits intogo-resty:v2from Mar 3, 2024
fabiante:feat/client-clone
Merged
Add Client.Clone function#774jeevatkm merged 3 commits intogo-resty:v2from fabiante:feat/client-clone
jeevatkm merged 3 commits intogo-resty:v2from
fabiante:feat/client-clone
Conversation
jeevatkm
requested changes
Feb 19, 2024
Member
jeevatkm
left a comment
There was a problem hiding this comment.
@fabiante Thanks for creating a draft. I have read the issue thread #773.
Can you please update the PR as follows?
Add a new method
// Clone returns a clone of the original client.
// <add further doc info here>
//
// Since v2.12.0
func (c *Client) Clone() *Client {
// dereference the pointer and copy the value
cc := *c
return &cc
}Change these field definitions to a pointer type.
udBeforeRequestLock *sync.RWMutex
.
.
.
afterResponseLock *sync.RWMutexFinally, initialize the fields while creating a new client
Line 1343 in 97187c4
jeevatkm
requested changes
Feb 21, 2024
jeevatkm
requested changes
Mar 2, 2024
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## v2 #774 +/- ##
==========================================
+ Coverage 96.46% 96.48% +0.01%
==========================================
Files 12 12
Lines 1643 1650 +7
==========================================
+ Hits 1585 1592 +7
Misses 37 37
Partials 21 21 ☔ View full report in Codecov by Sentry. |
renovate Bot
referenced
this pull request
in Michsior14/transmission-gluetun-port-update
Mar 18, 2024
[](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [github.com/go-resty/resty/v2](https://togithub.com/go-resty/resty) | `v2.11.0` -> `v2.12.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/) | --- ### Release Notes <details> <summary>go-resty/resty (github.com/go-resty/resty/v2)</summary> ### [`v2.12.0`](https://togithub.com/go-resty/resty/releases/tag/v2.12.0) [Compare Source](https://togithub.com/go-resty/resty/compare/v2.11.0...v2.12.0) ### Release Notes #### Enhancements - Add Client.Clone function by [@​fabiante](https://togithub.com/fabiante) in [https://github.com/go-resty/resty/pull/774](https://togithub.com/go-resty/resty/pull/774) #### Bug Fixes - Fixed JSON request logging data race. by [@​buglloc](https://togithub.com/buglloc) in [https://github.com/go-resty/resty/pull/775](https://togithub.com/go-resty/resty/pull/775) - fix: trailing NULL bytes in buffer while detecting a content type by [@​jeevatkm](https://togithub.com/jeevatkm) in [https://github.com/go-resty/resty/pull/779](https://togithub.com/go-resty/resty/pull/779) - fix: encode path params with BaseURL and the first param at index zero ([#​781](https://togithub.com/go-resty/resty/issues/781)) by [@​sakateka](https://togithub.com/sakateka) in [https://github.com/go-resty/resty/pull/782](https://togithub.com/go-resty/resty/pull/782) #### Documentation - fix: doc typo by [@​victoraugustolls](https://togithub.com/victoraugustolls) in [https://github.com/go-resty/resty/pull/769](https://togithub.com/go-resty/resty/pull/769) - docs: replace `SetHostURL` to `SetBaseURL` by [@​purofle](https://togithub.com/purofle) in [https://github.com/go-resty/resty/pull/772](https://togithub.com/go-resty/resty/pull/772) - for v2.12.0 release by [@​jeevatkm](https://togithub.com/jeevatkm) in [https://github.com/go-resty/resty/pull/783](https://togithub.com/go-resty/resty/pull/783) #### New Contributors - [@​victoraugustolls](https://togithub.com/victoraugustolls) made their first contribution in [https://github.com/go-resty/resty/pull/769](https://togithub.com/go-resty/resty/pull/769) - [@​purofle](https://togithub.com/purofle) made their first contribution in [https://github.com/go-resty/resty/pull/772](https://togithub.com/go-resty/resty/pull/772) - [@​buglloc](https://togithub.com/buglloc) made their first contribution in [https://github.com/go-resty/resty/pull/775](https://togithub.com/go-resty/resty/pull/775) - [@​fabiante](https://togithub.com/fabiante) made their first contribution in [https://github.com/go-resty/resty/pull/774](https://togithub.com/go-resty/resty/pull/774) - [@​sakateka](https://togithub.com/sakateka) made their first contribution in [https://github.com/go-resty/resty/pull/782](https://togithub.com/go-resty/resty/pull/782) **Full Changelog**: go-resty/resty@v2.11.0...v2.12.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **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/Michsior14/transmission-gluetun-port-update). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNDUuMCIsInVwZGF0ZWRJblZlciI6IjM3LjI0NS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a crude cloning function. It can be used to have a main client with default values and then create copies from that, which must use custom values.
The added function is rather crude and may introduce the potential that, when adding a new Client field, we forget to add it to Clone.
Thus, we should discuss if this is the right way to go. Using code generation or relflection might be a more maintainable solution.
Merging this PR would close #773