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

Make PathParams public #476

Merged
merged 1 commit into from Oct 31, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions client.go
Expand Up @@ -95,6 +95,7 @@ type Client struct {
HostURL string
QueryParam url.Values
FormData url.Values
PathParams map[string]string
Header http.Header
UserInfo *User
Token string
Expand Down Expand Up @@ -125,7 +126,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 @@ -367,7 +367,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 @@ -796,7 +796,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 @@ -1062,7 +1062,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