Skip to content

Commit d837dfc

Browse files
authored
Make PathParams public (#476)
1 parent eb1e112 commit d837dfc

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ type Client struct {
9696
HostURL string // Deprecated: use BaseURL instead. To be removed in v3.0.0 release.
9797
QueryParam url.Values
9898
FormData url.Values
99+
PathParams map[string]string
99100
Header http.Header
100101
UserInfo *User
101102
Token string
@@ -126,7 +127,6 @@ type Client struct {
126127
debugBodySizeLimit int64
127128
outputDirectory string
128129
scheme string
129-
pathParams map[string]string
130130
log Logger
131131
httpClient *http.Client
132132
proxyURL *url.URL
@@ -385,7 +385,7 @@ func (c *Client) R() *Request {
385385
client: c,
386386
multipartFiles: []*File{},
387387
multipartFields: []*MultipartField{},
388-
pathParams: map[string]string{},
388+
PathParams: map[string]string{},
389389
jsonEscapeHTML: true,
390390
}
391391
return r
@@ -814,7 +814,7 @@ func (c *Client) SetDoNotParseResponse(parse bool) *Client {
814814
// Also it can be overridden at request level Path Params options,
815815
// see `Request.SetPathParam` or `Request.SetPathParams`.
816816
func (c *Client) SetPathParam(param, value string) *Client {
817-
c.pathParams[param] = value
817+
c.PathParams[param] = value
818818
return c
819819
}
820820

@@ -1080,7 +1080,7 @@ func createClient(hc *http.Client) *Client {
10801080
jsonEscapeHTML: true,
10811081
httpClient: hc,
10821082
debugBodySizeLimit: math.MaxInt32,
1083-
pathParams: make(map[string]string),
1083+
PathParams: make(map[string]string),
10841084
}
10851085

10861086
// Logger

middleware.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ const debugRequestLogKey = "__restyDebugRequestLog"
2929

3030
func parseRequestURL(c *Client, r *Request) error {
3131
// GitHub #103 Path Params
32-
if len(r.pathParams) > 0 {
33-
for p, v := range r.pathParams {
32+
if len(r.PathParams) > 0 {
33+
for p, v := range r.PathParams {
3434
r.URL = strings.Replace(r.URL, "{"+p+"}", url.PathEscape(v), -1)
3535
}
3636
}
37-
if len(c.pathParams) > 0 {
38-
for p, v := range c.pathParams {
37+
if len(c.PathParams) > 0 {
38+
for p, v := range c.PathParams {
3939
r.URL = strings.Replace(r.URL, "{"+p+"}", url.PathEscape(v), -1)
4040
}
4141
}

request.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type Request struct {
3333
AuthScheme string
3434
QueryParam url.Values
3535
FormData url.Values
36+
PathParams map[string]string
3637
Header http.Header
3738
Time time.Time
3839
Body interface{}
@@ -60,7 +61,6 @@ type Request struct {
6061
fallbackContentType string
6162
forceContentType string
6263
ctx context.Context
63-
pathParams map[string]string
6464
values map[string]interface{}
6565
client *Client
6666
bodyBuf *bytes.Buffer
@@ -511,7 +511,7 @@ func (r *Request) SetDoNotParseResponse(parse bool) *Request {
511511
// It replaces the value of the key while composing the request URL. Also you can
512512
// override Path Params value, which was set at client instance level.
513513
func (r *Request) SetPathParam(param, value string) *Request {
514-
r.pathParams[param] = value
514+
r.PathParams[param] = value
515515
return r
516516
}
517517

0 commit comments

Comments
 (0)