mirror of https://github.com/gofiber/fiber.git
🐛 bug: fix client iterators when using break statement (#3357)
* 🐛 bug: fix client iterators when using break statement
* fix linter
pull/3366/head
parent
395c8fafa9
commit
87f3f0c8b6
|
@ -298,11 +298,12 @@ func (r *Request) Cookie(key string) string {
|
||||||
// Use maps.Collect() to gather them into a map if needed.
|
// Use maps.Collect() to gather them into a map if needed.
|
||||||
func (r *Request) Cookies() iter.Seq2[string, string] {
|
func (r *Request) Cookies() iter.Seq2[string, string] {
|
||||||
return func(yield func(string, string) bool) {
|
return func(yield func(string, string) bool) {
|
||||||
r.cookies.VisitAll(func(key, val string) {
|
for k, v := range *r.cookies {
|
||||||
if !yield(key, val) {
|
res := yield(k, v)
|
||||||
|
if !res {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,11 +344,11 @@ func (r *Request) PathParam(key string) string {
|
||||||
// Use maps.Collect() to gather them into a map if needed.
|
// Use maps.Collect() to gather them into a map if needed.
|
||||||
func (r *Request) PathParams() iter.Seq2[string, string] {
|
func (r *Request) PathParams() iter.Seq2[string, string] {
|
||||||
return func(yield func(string, string) bool) {
|
return func(yield func(string, string) bool) {
|
||||||
r.path.VisitAll(func(key, val string) {
|
for k, v := range *r.path {
|
||||||
if !yield(key, val) {
|
if !yield(k, v) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//nolint:goconst // Much easier to just ignore memory leaks in tests
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -451,6 +452,14 @@ func Test_Request_Cookies(t *testing.T) {
|
||||||
require.Equal(t, "bar", cookies["foo"])
|
require.Equal(t, "bar", cookies["foo"])
|
||||||
require.Equal(t, "foo", cookies["bar"])
|
require.Equal(t, "foo", cookies["bar"])
|
||||||
|
|
||||||
|
require.NotPanics(t, func() {
|
||||||
|
for _, v := range req.Cookies() {
|
||||||
|
if v == "bar" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
require.Len(t, cookies, 2)
|
require.Len(t, cookies, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -564,6 +573,14 @@ func Test_Request_PathParams(t *testing.T) {
|
||||||
require.Equal(t, "foo", pathParams["bar"])
|
require.Equal(t, "foo", pathParams["bar"])
|
||||||
|
|
||||||
require.Len(t, pathParams, 2)
|
require.Len(t, pathParams, 2)
|
||||||
|
|
||||||
|
require.NotPanics(t, func() {
|
||||||
|
for _, v := range req.PathParams() {
|
||||||
|
if v == "bar" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func Benchmark_Request_PathParams(b *testing.B) {
|
func Benchmark_Request_PathParams(b *testing.B) {
|
||||||
|
@ -1579,7 +1596,7 @@ func Test_SetValWithStruct(t *testing.T) {
|
||||||
|
|
||||||
require.True(t, func() bool {
|
require.True(t, func() bool {
|
||||||
for _, v := range p.PeekMulti("TSlice") {
|
for _, v := range p.PeekMulti("TSlice") {
|
||||||
if string(v) == "bar" { //nolint:goconst // test
|
if string(v) == "bar" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue