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

♻️ Refactor: Rename the Method Names of FormData and FormDatas (#3251) #3255

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ func setConfigToRequest(req *Request, config ...Config) {
}

if cfg.FormData != nil {
req.SetFormDatas(cfg.FormData)
req.SetFormDataWithMap(cfg.FormData)
return
}

Expand Down
6 changes: 3 additions & 3 deletions client/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func Test_Parser_Request_Header(t *testing.T) {
t.Parallel()
client := New()
req := AcquireRequest().
SetFormDatas(map[string]string{
SetFormDataWithMap(map[string]string{
"foo": "bar",
"ball": "cricle and square",
})
Expand Down Expand Up @@ -485,7 +485,7 @@ func Test_Parser_Request_Body(t *testing.T) {
t.Parallel()
client := New()
req := AcquireRequest().
SetFormDatas(map[string]string{
SetFormDataWithMap(map[string]string{
"ball": "cricle and square",
})

Expand All @@ -498,7 +498,7 @@ func Test_Parser_Request_Body(t *testing.T) {
t.Parallel()
client := New()
req := AcquireRequest().
SetFormDatas(map[string]string{
SetFormDataWithMap(map[string]string{
"": "",
})

Expand Down
58 changes: 29 additions & 29 deletions client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,42 +460,42 @@ func (r *Request) AllFormData() iter.Seq2[string, []string] {

// AddFormData adds a single form field and value to the Request.
func (r *Request) AddFormData(key, val string) *Request {
r.formData.AddData(key, val)
r.formData.Add(key, val)
r.resetBody(formBody)
return r
}

// SetFormData sets a single form field and value, overriding any previously set value.
func (r *Request) SetFormData(key, val string) *Request {
r.formData.SetData(key, val)
r.formData.Set(key, val)
r.resetBody(formBody)
return r
}

// AddFormDatas adds multiple form fields and values to the Request.
func (r *Request) AddFormDatas(m map[string][]string) *Request {
r.formData.AddDatas(m)
// AddFormDataWithMap adds multiple form fields and values to the Request.
func (r *Request) AddFormDataWithMap(m map[string][]string) *Request {
r.formData.AddWithMap(m)
r.resetBody(formBody)
return r
}

// SetFormDatas sets multiple form fields and values at once, overriding previously set values.
func (r *Request) SetFormDatas(m map[string]string) *Request {
r.formData.SetDatas(m)
// SetFormDataWithMap sets multiple form fields and values at once, overriding previously set values.
func (r *Request) SetFormDataWithMap(m map[string]string) *Request {
r.formData.SetWithMap(m)
r.resetBody(formBody)
return r
}

// SetFormDatasWithStruct sets multiple form fields from a struct, overriding previously set values.
func (r *Request) SetFormDatasWithStruct(v any) *Request {
r.formData.SetDatasWithStruct(v)
// SetFormDataWithStruct sets multiple form fields from a struct, overriding previously set values.
func (r *Request) SetFormDataWithStruct(v any) *Request {
r.formData.SetWithStruct(v)
r.resetBody(formBody)
return r
}

// DelFormDatas deletes one or more form fields.
func (r *Request) DelFormDatas(key ...string) *Request {
r.formData.DelDatas(key...)
// DelFormData deletes one or more form fields.
func (r *Request) DelFormData(key ...string) *Request {
r.formData.DelData(key...)
r.resetBody(formBody)
return r
}
Expand Down Expand Up @@ -845,42 +845,42 @@ func (f *FormData) Keys() []string {
return slices.Compact(keys)
}

// AddData adds a single form field.
func (f *FormData) AddData(key, val string) {
f.Add(key, val)
// Add adds a single form field.
func (f *FormData) Add(key, val string) {
f.Args.Add(key, val)
}

// SetData sets a single form field, overriding previously set values.
func (f *FormData) SetData(key, val string) {
f.Set(key, val)
// Set sets a single form field, overriding previously set values.
func (f *FormData) Set(key, val string) {
f.Args.Set(key, val)
}

// AddDatas adds multiple form fields from a map.
func (f *FormData) AddDatas(m map[string][]string) {
// AddWithMap adds multiple form fields from a map.
func (f *FormData) AddWithMap(m map[string][]string) {
for k, v := range m {
for _, vv := range v {
f.Add(k, vv)
}
}
}

// SetDatas sets multiple form fields from a map, overriding previously set values.
func (f *FormData) SetDatas(m map[string]string) {
// SetWithMap sets multiple form fields from a map, overriding previously set values.
func (f *FormData) SetWithMap(m map[string]string) {
for k, v := range m {
f.Set(k, v)
}
}

// SetDatasWithStruct sets multiple form fields from a struct.
// SetWithStruct sets multiple form fields from a struct.
// Nested structs are not currently supported.
func (f *FormData) SetDatasWithStruct(v any) {
func (f *FormData) SetWithStruct(v any) {
SetValWithStruct(f, "form", v)
}

// DelDatas deletes multiple form fields.
func (f *FormData) DelDatas(key ...string) {
// DelData deletes multiple form fields.
func (f *FormData) DelData(key ...string) {
for _, v := range key {
f.Del(v)
f.Args.Del(v)
}
}

Expand Down
16 changes: 8 additions & 8 deletions client/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ func Test_Request_FormData(t *testing.T) {
req := AcquireRequest()
defer ReleaseRequest(req)
req.SetFormData("foo", "bar").
AddFormDatas(map[string][]string{
AddFormDataWithMap(map[string][]string{
"foo": {"fiber", "buaa"},
"bar": {"foo"},
})
Expand All @@ -636,7 +636,7 @@ func Test_Request_FormData(t *testing.T) {
req := AcquireRequest()
defer ReleaseRequest(req)
req.SetFormData("foo", "bar").
SetFormDatas(map[string]string{
SetFormDataWithMap(map[string]string{
"foo": "fiber",
"bar": "foo",
})
Expand Down Expand Up @@ -664,7 +664,7 @@ func Test_Request_FormData(t *testing.T) {

p := AcquireRequest()
defer ReleaseRequest(p)
p.SetFormDatasWithStruct(&args{
p.SetFormDataWithStruct(&args{
TInt: 5,
TString: "string",
TFloat: 3.1,
Expand Down Expand Up @@ -702,10 +702,10 @@ func Test_Request_FormData(t *testing.T) {
req := AcquireRequest()
defer ReleaseRequest(req)
req.SetFormData("foo", "bar").
SetFormDatas(map[string]string{
SetFormDataWithMap(map[string]string{
"foo": "fiber",
"bar": "foo",
}).DelFormDatas("foo", "bar")
}).DelFormData("foo", "bar")

res := req.FormData("foo")
require.Empty(t, res)
Expand Down Expand Up @@ -1212,7 +1212,7 @@ func Test_Request_Body_With_Server(t *testing.T) {
},
func(agent *Request) {
agent.SetFormData("foo", "bar").
SetFormDatas(map[string]string{
SetFormDataWithMap(map[string]string{
"bar": "baz",
"fiber": "fast",
})
Expand Down Expand Up @@ -1362,7 +1362,7 @@ func Test_Request_AllFormData(t *testing.T) {
t.Parallel()

req := AcquireRequest()
req.AddFormDatas(map[string][]string{
req.AddFormDataWithMap(map[string][]string{
"foo": {"bar", "fiber"},
"bar": {"foo"},
})
Expand All @@ -1378,7 +1378,7 @@ func Test_Request_AllFormData(t *testing.T) {

func Benchmark_Request_AllFormData(b *testing.B) {
req := AcquireRequest()
req.AddFormDatas(map[string][]string{
req.AddFormDataWithMap(map[string][]string{
"foo": {"bar", "fiber"},
"bar": {"foo"},
})
Expand Down
60 changes: 30 additions & 30 deletions docs/client/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -825,36 +825,36 @@ fmt.Println(string(resp.Body()))

</details>

### AddFormDatas
### AddFormDataWithMap

**AddFormDatas** adds multiple form data fields and values from a map of string slices.
**AddFormDataWithMap** adds multiple form data fields and values from a map of string slices.

```go title="Signature"
func (r *Request) AddFormDatas(m map[string][]string) *Request
func (r *Request) AddFormDataWithMap(m map[string][]string) *Request
```

### SetFormDatas
### SetFormDataWithMap

**SetFormDatas** sets multiple form data fields from a map of strings.
**SetFormDataWithMap** sets multiple form data fields from a map of strings.

```go title="Signature"
func (r *Request) SetFormDatas(m map[string]string) *Request
func (r *Request) SetFormDataWithMap(m map[string]string) *Request
```

### SetFormDatasWithStruct
### SetFormDataWithStruct

**SetFormDatasWithStruct** sets multiple form data fields from a struct.
**SetFormDataWithStruct** sets multiple form data fields from a struct.

```go title="Signature"
func (r *Request) SetFormDatasWithStruct(v any) *Request
func (r *Request) SetFormDataWithStruct(v any) *Request
```

### DelFormDatas
### DelFormData

**DelFormDatas** deletes one or more form data fields by their keys.
**DelFormData** deletes one or more form data fields by their keys.

```go title="Signature"
func (r *Request) DelFormDatas(key ...string) *Request
func (r *Request) DelFormData(key ...string) *Request
```

## File
Expand Down Expand Up @@ -1311,52 +1311,52 @@ type FormData struct {
func (f *FormData) Keys() []string
```

### AddData
### Add

**AddData** adds a single form field key-value pair.
**Add** adds a single form field key-value pair.

```go title="Signature"
func (f *FormData) AddData(key, val string)
func (f *FormData) Add(key, val string)
```

### SetData
### Set

**SetData** sets a single form field key-value pair, overriding any previously set values.
**Set** sets a single form field key-value pair, overriding any previously set values.

```go title="Signature"
func (f *FormData) SetData(key, val string)
func (f *FormData) Set(key, val string)
```

### AddDatas
### AddWithMap

**AddDatas** adds multiple form fields from a map of string slices.
**AddWithMap** adds multiple form fields from a map of string slices.

```go title="Signature"
func (f *FormData) AddDatas(m map[string][]string)
func (f *FormData) AddWithMap(m map[string][]string)
```

### SetDatas
### SetWithMap

**SetDatas** sets multiple form fields from a map of strings.
**SetWithMap** sets multiple form fields from a map of strings.

```go title="Signature"
func (f *FormData) SetDatas(m map[string]string)
func (f *FormData) SetWithMap(m map[string]string)
```

### SetDatasWithStruct
### SetWithStruct

**SetDatasWithStruct** sets multiple form fields from a struct.
**SetWithStruct** sets multiple form fields from a struct.

```go title="Signature"
func (f *FormData) SetDatasWithStruct(v any)
func (f *FormData) SetWithStruct(v any)
```

### DelDatas
### DelData

**DelDatas** deletes one or more form fields by their keys.
**DelData** deletes one or more form fields by their keys.

```go title="Signature"
func (f *FormData) DelDatas(key ...string)
func (f *FormData) DelData(key ...string)
```

### Reset
Expand Down
Loading