8000 [pull] master from go-resty:master by pull[bot] · Pull Request #5 · r0ck3rt/resty · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[pull] master from go-resty:master #5

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

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open

Conversation

pull[bot]
Copy link
@pull pull bot commented Sep 17, 2023

See Commits and Changes for more details.


Created by pull[bot]

Can you help keep this open source service alive? 💖 Please sponsor : )

@pull pull bot added the ⤵️ pull label Sep 17, 2023
haivp3010 and others added 18 commits September 17, 2023 11:18
* set request error to nil upon 204 No Content response

* fix empty body check (ioutil.ReadAll will return an empty slice rather than nil https://go.googlesource.com/go/+/refs/tags/go1.16/src/io/io.go#627)
The documentation about the order of middleware application
for OnBeforeRequet was different from the implementation. Fixed this by
changing the documentation.

Fixes #686.
SVilgelm and others added 9 commits September 24, 2023 21:35
* unit tests for the `PathParams`, `RawPathParams` and `QueryParams` added by client and request
* unit tests for `client.HostURL` and `client.BaseURL`
* use `client.BaseURL` by default and fallback to `client.HostURL` if empty
In case of using `t.Parallel()` inside a for loop, the loop variables must be copied, otherwise only the last test will be executed.

```go
	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			t.Parallel()
```
changed to
```go
	for _, test := range tests {
		test := test
		t.Run(test.name, func(t *testing.T) {
			t.Parallel()
```

also the AuthServer must be created within the test, otherwise some tests fail.

`t.Log(test.Name)` can be used to verify the issue:
```go
	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			t.Parallel()
			t.Log("Test name:", test.name)
```
…arks (#712)

* Benchmarks and Unit tests for parseRequestHeader function

```shell
% go test -benchmem -bench=. -run=^Benchmark
goos: darwin
goarch: amd64
pkg: github.com/go-resty/resty/v2
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Benchmark_parseRequestHeader-16          1168611              1042 ns/op             496 B/op          8 allocs/op
PASS
ok      github.com/go-resty/resty/v2    2.383s
```

* improve the performance of parseRequestHeader

```shell
% go test -benchmem -bench=. -run=^Benchmark
goos: darwin
goarch: amd64
pkg: github.com/go-resty/resty/v2
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Benchmark_parseRequestHeader-16          7956481               155.6 ns/op             0 B/op          0 allocs/op
PASS
ok      github.com/go-resty/resty/v2    1.599s
```
* add rate limiter to client

* make rate limiter work for retries

* make rate limiter return error instead of blocking

* fix test

* use RateLimiter interface instead of x/time/rate

---------

Co-authored-by: David Linus Briemann <dlb@mailbox.org>
* Unit tests and Benchmarks for parseRequestBody function

```shell
% go test -benchmem -bench=. -run=^Benchmark
goos: darwin
goarch: amd64
pkg: github.com/go-resty/resty/v2
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Benchmark_parseRequestBody_string-16                                     2194669               550.2 ns/op           128 B/op          3 allocs/op
Benchmark_parseRequestBody_byte-16                                       2260675               531.5 ns/op           128 B/op          3 allocs/op
Benchmark_parseRequestBody_reader_with_SetContentLength-16               8393974               141.4 ns/op            16 B/op          1 allocs/op
Benchmark_parseRequestBody_reader_without_SetContentLength-16           14253069                84.30 ns/op            0 B/op          0 allocs/op
Benchmark_parseRequestBody_struct-16                                      880549              1307 ns/op             155 B/op          5 allocs/op
Benchmark_parseRequestBody_struct_xml-16                                  424707              2886 ns/op            4762 B/op         13 allocs/op
Benchmark_parseRequestBody_map-16                                         547629              2152 ns/op             569 B/op         15 allocs/op
Benchmark_parseRequestBody_slice-16                                       959576              1264 ns/op             146 B/op          4 allocs/op
Benchmark_parseRequestBody_FormData-16                                    973964              1243 ns/op             304 B/op         14 allocs/op
Benchmark_parseRequestBody_MultiPart-16                                    98246             12320 ns/op            8746 B/op        131 allocs/op
```

* improve handleFormData

Benchmarks:
```
Old: Benchmark_parseRequestBody_FormData-16            954213              1266 ns/op             304 B/op         14 allocs/op
New: Benchmark_parseRequestBody_FormData-16            968466              1248 ns/op             280 B/op         10 allocs/op
```

* improve handleRequestBody

Benchmarks:
```
Old:
Benchmark_parseRequestBody_string-16             2199196               550.3 ns/op           128 B/op          3 allocs/op
Benchmark_parseRequestBody_byte-16               2264421               532.9 ns/op           128 B/op          3 allocs/op
Benchmark_parseRequestBody_reader-16             8307141               141.8 ns/op            16 B/op          1 allocs/op
Benchmark_parseRequestBody_struct-16              931632              1317 ns/op             156 B/op          5 allocs/op
Benchmark_parseRequestBody_struct_xml-16          409074              2921 ns/op            4765 B/op         13 allocs/op
Benchmark_parseRequestBody_map-16                 566750              2158 ns/op             570 B/op         15 allocs/op
Benchmark_parseRequestBody_slice-16               957828              1279 ns/op             146 B/op          4 allocs/op

New:
Benchmark_parseRequestBody_string-16             5084247               237.0 ns/op            16 B/op          1 allocs/op
Benchmark_parseRequestBody_byte-16               5298362               218.0 ns/op            16 B/op          1 allocs/op
Benchmark_parseRequestBody_reader-16             8402954               141.3 ns/op            16 B/op          1 allocs/op
Benchmark_parseRequestBody_struct-16             1000000              1066 ns/op              42 B/op          3 allocs/op
Benchmark_parseRequestBody_struct_xml-16          452389              2575 ns/op            4648 B/op         11 allocs/op
Benchmark_parseRequestBody_map-16                 620391              1913 ns/op             457 B/op         13 allocs/op
Benchmark_parseRequestBody_slice-16              1207551              1203 ns/op              32 B/op          2 allocs/op
```

* improve parseRequesBody and add additional benchmarks

Final benchmarks:
```s
8000
hell
 % go test -benchmem -bench=. -run=^Benchmark
goos: darwin
goarch: amd64
pkg: github.com/go-resty/resty/v2
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Benchmark_parseRequestBody_string-16                                     7623501               155.3 ns/op            16 B/op          1 allocs/op
Benchmark_parseRequestBody_byte-16                                       8421992               141.6 ns/op            16 B/op          1 allocs/op
Benchmark_parseRequestBody_reader_with_SetContentLength-16              17632350                67.37 ns/op           16 B/op          1 allocs/op
Benchmark_parseRequestBody_reader_without_SetContentLength-16           26575016                45.34 ns/op            0 B/op          0 allocs/op
Benchmark_parseRequestBody_struct-16                                     1243986               953.8 ns/op            40 B/op          2 allocs/op
Benchmark_parseRequestBody_struct_xml-16                                  495250              2458 ns/op            4647 B/op         10 allocs/op
Benchmark_parseRequestBody_map-16                                         694786              1761 ns/op             454 B/op         12 allocs/op
Benchmark_parseRequestBody_slice-16                                      1304724               913.1 ns/op            32 B/op          2 allocs/op
Benchmark_parseRequestBody_FormData-16                                   1000000              1128 ns/op             272 B/op          9 allocs/op
Benchmark_parseRequestBody_MultiPart-16                                    93248             12583 ns/op            8738 B/op        130 allocs/op
```

* add error test cases

* use r.FormData inatead of creating new variable
* Benchmarks for applying PathParams in parseRequestURL function

```shell
% go test -benchmem -bench=. -run=^Benchmark
goos: darwin
goarch: amd64
pkg: github.com/go-resty/resty/v2
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Benchmark_parseRequestURL_PathParams-16           524658              2260 ns/op             448 B/op          9 allocs/op
PASS
ok      github.com/go-resty/resty/v2    2.327s
```

* Benchmarks for applying QueryParams in parseRequestURL function

```shell
% go test -benchmem -bench=. -run=^Benchmark
goos: darwin
goarch: amd64
pkg: github.com/go-resty/resty/v2
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Benchmark_parseRequestURL_QueryParams-16          865923              1371 ns/op             416 B/op         13 allocs/op
PASS
ok      github.com/go-resty/resty/v2    2.491s
```

* improve the performance of applying the path parameters

* Use the map to collect all replacements and use replace all path parameters using O(1) logic
* Add additional unit tests to cover empty `{}` and not closed `{bar` path parameters

```shell
% go test -benchmem -bench=. -run=^Benchmark
goos: darwin
goarch: amd64
pkg: github.com/go-resty/resty/v2
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Benchmark_parseRequestURL_PathParams-16           785971              1410 ns/op             320 B/op          6 allocs/op
PASS
ok      github.com/go-resty/resty/v2    1.445s
```

* improve the performance of applying the query parameters

* improve the loging by adding the query parameters from the request first, then adding the parameters from the client and skip if already exists
* additional unit tests for the query parameters

```shell
% go test -benchmem -bench=. -run=^Benchmark
goos: darwin
goarch: amd64
pkg: github.com/go-resty/resty/v2
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Benchmark_parseRequestURL_QueryParams-16         1000000              1158 ns/op             352 B/op          9 allocs/op
PASS
ok      github.com/go-resty/resty/v2    2.473s
```

* using acquireBuffer

reusing a buffer from the pool decreases the allocs and memory usage

```shell
% go test -benchmem -bench=. -run=^Benchmark
goos: darwin
goarch: amd64
pkg: github.com/go-resty/resty/v2
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Benchmark_parseRequestURL_PathParams-16           753834              1367 ns/op             256 B/op          5 allocs/op
Benchmark_parseRequestURL_QueryParams-16         1000000              1167 ns/op             352 B/op          9 allocs/op
PASS
ok      github.com/go-resty/resty/v2    2.373s
```

* using reflect.DeepEqual to compare the expected and actual QueryParams

* update r.QueryParam isntead of creating new variable

* remove unneeded if
@jeevatkm jeevatkm deleted the branch r0ck3rt:master October 8, 2023 03:34
@jeevatkm jeevatkm deleted the master branch October 8, 2023 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0