Skip to content
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

🔥 feat: Add support for creating Fiber client from existing FastHTTP client #3214

Merged
merged 7 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,13 @@ func New() *Client {
// trie to use a pool to reduce the cost of memory allocation
// for the fiber client and the fasthttp client
// if possible also for other structs -> request header, cookie, query param, path param...
return NewWithClient(&fasthttp.Client{})
}

// NewWithClient creates and returns a new Client object from an existing client.
func NewWithClient(c *fasthttp.Client) *Client {
gaby marked this conversation as resolved.
Show resolved Hide resolved
mitulagr2 marked this conversation as resolved.
Show resolved Hide resolved
return &Client{
fasthttp: &fasthttp.Client{},
fasthttp: c,
header: &Header{
RequestHeader: &fasthttp.RequestHeader{},
},
Expand Down
11 changes: 11 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ func startTestServerWithPort(t *testing.T, beforeStarting func(app *fiber.App))
return nil, ""
}

func Test_New_With_Client(t *testing.T) {
t.Parallel()

c := &fasthttp.Client{
MaxConnsPerHost: 5,
}
client := NewWithClient(c)

require.NotNil(t, client)
}
gaby marked this conversation as resolved.
Show resolved Hide resolved

func Test_Client_Add_Hook(t *testing.T) {
t.Parallel()

Expand Down
10 changes: 9 additions & 1 deletion docs/client/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,22 @@ type Client struct {
}
```

New
### New

New creates and returns a new Client object.

```go title="Signature"
func New() *Client
```

### NewWithClient

NewWithClient creates and returns a new Client object from an existing client object.

```go title="Signature"
func NewWithClient(c *fasthttp.Client) *Client
```

## REST Methods

### Get
Expand Down
Loading