Skip to content

Commit

Permalink
Support Request.SetQueryParamsAnyType
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Aug 8, 2022
1 parent 0029353 commit d0ecd07
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,15 @@ func (r *Request) SetQueryParams(params map[string]string) *Request {
return r
}

// SetQueryParamsAnyType set URL query parameters from a map for the request.
// The value of map is any type, will be convert to string automatically.
func (r *Request) SetQueryParamsAnyType(params map[string]interface{}) *Request {
for k, v := range params {
r.SetQueryParam(k, fmt.Sprint(v))
}
return r
}

// SetQueryParam set an URL query parameter for the request.
func (r *Request) SetQueryParam(key, value string) *Request {
if r.QueryParams == nil {
Expand Down
6 changes: 6 additions & 0 deletions request_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ func SetQueryParams(params map[string]string) *Request {
return defaultClient.R().SetQueryParams(params)
}

// SetQueryParamsAnyType is a global wrapper methods which delegated
// to the default client, create a request and SetQueryParamsAnyType for request.
func SetQueryParamsAnyType(params map[string]interface{}) *Request {
return defaultClient.R().SetQueryParamsAnyType(params)
}

// SetQueryParam is a global wrapper methods which delegated
// to the default client, create a request and SetQueryParam for request.
func SetQueryParam(key, value string) *Request {
Expand Down

0 comments on commit d0ecd07

Please sign in to comment.