From d837dfc6d620a84240a2a3186182dee2517834d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lavoie?= Date: Sat, 30 Oct 2021 21:07:49 -0400 Subject: [PATCH] Make PathParams public (#476) --- client.go | 8 ++++---- middleware.go | 8 ++++---- request.go | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/client.go b/client.go index eb12f086..d1bcada1 100644 --- a/client.go +++ b/client.go @@ -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 @@ -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 @@ -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 @@ -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 } @@ -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 diff --git a/middleware.go b/middleware.go index 60b1ebad..866fb4d1 100644 --- a/middleware.go +++ b/middleware.go @@ -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) } } diff --git a/request.go b/request.go index 1cd42cf7..672df88c 100644 --- a/request.go +++ b/request.go @@ -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{} @@ -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 @@ -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 }