Skip to content

Commit

Permalink
Make PathParams public (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
lavoiesl committed Oct 31, 2021
1 parent eb1e112 commit d837dfc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions client.go
Expand Up @@ -96,6 +96,7 @@ type Client struct {
HostURL string // Deprecated: use BaseURL instead. To be removed in v3.0.0 release.
QueryParam url.Values
FormData url.Values
PathParams map[string]string
Header http.Header
UserInfo *User
Token string
Expand Down Expand Up @@ -126,7 +127,6 @@ type Client struct {
debugBodySizeLimit int64
outputDirectory string
scheme string
pathParams map[string]string
log Logger
httpClient *http.Client
proxyURL *url.URL
Expand Down Expand Up @@ -385,7 +385,7 @@ func (c *Client) R() *Request {
client: c,
multipartFiles: []*File{},
multipartFields: []*MultipartField{},
pathParams: map[string]string{},
PathParams: map[string]string{},
jsonEscapeHTML: true,
}
return r
Expand Down Expand Up @@ -814,7 +814,7 @@ func (c *Client) SetDoNotParseResponse(parse bool) *Client {
// Also it can be overridden at request level Path Params options,
// see `Request.SetPathParam` or `Request.SetPathParams`.
func (c *Client) SetPathParam(param, value string) *Client {
c.pathParams[param] = value
c.PathParams[param] = value
return c
}

Expand Down Expand Up @@ -1080,7 +1080,7 @@ func createClient(hc *http.Client) *Client {
jsonEscapeHTML: true,
httpClient: hc,
debugBodySizeLimit: math.MaxInt32,
pathParams: make(map[string]string),
PathParams: make(map[string]string),
}

// Logger
Expand Down
8 changes: 4 additions & 4 deletions middleware.go
Expand Up @@ -29,13 +29,13 @@ const debugRequestLogKey = "__restyDebugRequestLog"

func parseRequestURL(c *Client, r *Request) error {
// GitHub #103 Path Params
if len(r.pathParams) > 0 {
for p, v := range r.pathParams {
if len(r.PathParams) > 0 {
for p, v := range r.PathParams {
r.URL = strings.Replace(r.URL, "{"+p+"}", url.PathEscape(v), -1)
}
}
if len(c.pathParams) > 0 {
for p, v := range c.pathParams {
if len(c.PathParams) > 0 {
for p, v := range c.PathParams {
r.URL = strings.Replace(r.URL, "{"+p+"}", url.PathEscape(v), -1)
}
}
Expand Down
4 changes: 2 additions & 2 deletions request.go
Expand Up @@ -33,6 +33,7 @@ type Request struct {
AuthScheme string
QueryParam url.Values
FormData url.Values
PathParams map[string]string
Header http.Header
Time time.Time
Body interface{}
Expand Down Expand Up @@ -60,7 +61,6 @@ type Request struct {
fallbackContentType string
forceContentType string
ctx context.Context
pathParams map[string]string
values map[string]interface{}
client *Client
bodyBuf *bytes.Buffer
Expand Down Expand Up @@ -511,7 +511,7 @@ func (r *Request) SetDoNotParseResponse(parse bool) *Request {
// It replaces the value of the key while composing the request URL. Also you can
// override Path Params value, which was set at client instance level.
func (r *Request) SetPathParam(param, value string) *Request {
r.pathParams[param] = value
r.PathParams[param] = value
return r
}

Expand Down

0 comments on commit d837dfc

Please sign in to comment.