Skip to content

Commit

Permalink
docs: godoc update
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Nov 17, 2024
1 parent e134807 commit 7cc8a14
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 36 deletions.
44 changes: 24 additions & 20 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,9 @@ func (c *Client) SetHeader(header, value string) *Client {
// For Example: To set `Content-Type` and `Accept` as `application/json`
//
// client.SetHeaders(map[string]string{
// "Content-Type": "application/json",
// "Accept": "application/json",
// })
// "Content-Type": "application/json",
// "Accept": "application/json",
// })
func (c *Client) SetHeaders(headers map[string]string) *Client {
c.lock.Lock()
defer c.lock.Unlock()
Expand All @@ -328,13 +328,15 @@ func (c *Client) SetHeaders(headers map[string]string) *Client {
return c
}

// SetHeaderVerbatim method sets a single header field and its value verbatim in the current request.
// SetHeaderVerbatim method is used to set the HTTP header key and value verbatim in the current request.
// It is typically helpful for legacy applications or servers that require HTTP headers in a certain way
//
// For Example: To set `all_lowercase` and `UPPERCASE` as `available`.
// For Example: To set header key as `all_lowercase`, `UPPERCASE`, and `x-cloud-trace-id`
//
// client.
// SetHeaderVerbatim("all_lowercase", "available").
// SetHeaderVerbatim("UPPERCASE", "available")
// SetHeaderVerbatim("UPPERCASE", "available").
// SetHeaderVerbatim("x-cloud-trace-id", "798e94019e5fc4d57fbb8901eb4c6cae")
func (c *Client) SetHeaderVerbatim(header, value string) *Client {
c.lock.Lock()
defer c.lock.Unlock()
Expand Down Expand Up @@ -387,9 +389,9 @@ func (c *Client) Cookies() []*http.Cookie {
// These cookies will be added to all the requests from this client instance.
//
// client.SetCookie(&http.Cookie{
// Name:"go-resty",
// Value:"This is cookie value",
// })
// Name:"go-resty",
// Value:"This is cookie value",
// })
func (c *Client) SetCookie(hc *http.Cookie) *Client {
c.lock.Lock()
defer c.lock.Unlock()
Expand Down Expand Up @@ -458,9 +460,9 @@ func (c *Client) SetQueryParam(param, value string) *Client {
// See [Request.SetQueryParams] or [Request.SetQueryParam].
//
// client.SetQueryParams(map[string]string{
// "search": "kitchen papers",
// "size": "large",
// })
// "search": "kitchen papers",
// "size": "large",
// })
func (c *Client) SetQueryParams(params map[string]string) *Client {
// Do not lock here since there is potential deadlock.
for p, v := range params {
Expand All @@ -484,9 +486,9 @@ func (c *Client) FormData() url.Values {
// See [Request.SetFormData].
//
// client.SetFormData(map[string]string{
// "access_token": "BC594900-518B-4F7E-AC75-BD37F019E08F",
// "user_id": "3455454545",
// })
// "access_token": "BC594900-518B-4F7E-AC75-BD37F019E08F",
// "user_id": "3455454545",
// })
func (c *Client) SetFormData(data map[string]string) *Client {
c.lock.Lock()
defer c.lock.Unlock()
Expand Down Expand Up @@ -979,6 +981,8 @@ func (c *Client) DisableDebug() *Client {
// of every request and response.
//
// client.SetDebug(true)
// // OR
// client.EnableDebug()
//
// Also, it can be enabled at the request level for a particular request; see [Request.SetDebug].
// - For [Request], it logs information such as HTTP verb, Relative URL path,
Expand Down Expand Up @@ -1473,10 +1477,10 @@ func (c *Client) SetRootCertificate(pemFilePath string) *Client {
// The caller is responsible for calling Close to stop the watcher.
//
// client.SetRootCertificateWatcher("root-ca.crt", &CertWatcherOptions{
// PoolInterval: time.Hour * 24,
// PoolInterval: time.Hour * 24,
// })
//
// defer client.Close()
// defer client.Close()
func (c *Client) SetRootCertificateWatcher(pemFilePath string, options *CertWatcherOptions) *Client {
c.SetRootCertificate(pemFilePath)
c.initCertWatcher(pemFilePath, "root", options)
Expand Down Expand Up @@ -1511,9 +1515,9 @@ func (c *Client) SetClientRootCertificate(pemFilePath string) *Client {
// The caller is responsible for calling Close to stop the watcher.
//
// client.SetClientRootCertificateWatcher("root-ca.crt", &CertWatcherOptions{
// PoolInterval: time.Hour * 24,
// })
// defer client.Close()
// PoolInterval: time.Hour * 24,
// })
// defer client.Close()
func (c *Client) SetClientRootCertificateWatcher(pemFilePath string, options *CertWatcherOptions) *Client {
c.SetClientRootCertificate(pemFilePath)
c.initCertWatcher(pemFilePath, "client", options)
Expand Down
36 changes: 20 additions & 16 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,15 @@ func (r *Request) SetHeaderMultiValues(headers map[string][]string) *Request {
return r
}

// SetHeaderVerbatim method sets a single header field and its value verbatim in the current request.
// SetHeaderVerbatim method is used to set the HTTP header key and value verbatim in the current request.
// It is typically helpful for legacy applications or servers that require HTTP headers in a certain way
//
// For Example: To set `all_lowercase` and `UPPERCASE` as `available`.
// For Example: To set header key as `all_lowercase`, `UPPERCASE`, and `x-cloud-trace-id`
//
// client.R().
// SetHeaderVerbatim("all_lowercase", "available").
// SetHeaderVerbatim("UPPERCASE", "available")
// SetHeaderVerbatim("UPPERCASE", "available").
// SetHeaderVerbatim("x-cloud-trace-id", "798e94019e5fc4d57fbb8901eb4c6cae")
//
// It overrides the header value set at the client instance level.
func (r *Request) SetHeaderVerbatim(header, value string) *Request {
Expand Down Expand Up @@ -471,10 +473,10 @@ func (r *Request) SetFile(fieldName, filePath string) *Request {
//
// client.R().
// SetFiles(map[string]string{
// "my_file1": "/Users/jeeva/Gas Bill - Sep.pdf",
// "my_file2": "/Users/jeeva/Electricity Bill - Sep.pdf",
// "my_file3": "/Users/jeeva/Water Bill - Sep.pdf",
// })
// "my_file1": "/Users/jeeva/Gas Bill - Sep.pdf",
// "my_file2": "/Users/jeeva/Electricity Bill - Sep.pdf",
// "my_file3": "/Users/jeeva/Water Bill - Sep.pdf",
// })
func (r *Request) SetFiles(files map[string]string) *Request {
r.isMultiPart = true
for f, fp := range files {
Expand Down Expand Up @@ -947,7 +949,9 @@ func (r *Request) DisableDebug() *Request {
// SetDebug method enables the debug mode on the current request. It logs
// the details current request and response.
//
// client.SetDebug(true)
// client.R().SetDebug(true)
// // OR
// client.R().EnableDebug()
//
// Also, it can be enabled at the request level for a particular request; see [Request.SetDebug].
// - For [Request], it logs information such as HTTP verb, Relative URL path,
Expand Down Expand Up @@ -1228,10 +1232,10 @@ func (r *Request) Trace(url string) (*Response, error) {
// Send method performs the HTTP request using the method and URL already defined
// for current [Request].
//
// req := client.R()
// req.Method = resty.MethodGet
// req.URL = "http://httpbin.org/get"
// resp, err := req.Send()
// res, err := client.R().
// SetMethod(resty.MethodGet).
// SetURL("http://httpbin.org/get").
// Send()
func (r *Request) Send() (*Response, error) {
return r.Execute(r.Method, r.URL)
}
Expand Down Expand Up @@ -1371,10 +1375,10 @@ func (r *Request) Execute(method, url string) (res *Response, err error) {
//
// The body is not copied, but it's a reference to the original body.
//
// request := client.R()
// request.SetBody("body")
// request.SetHeader("header", "value")
// clonedRequest := request.Clone(context.Background())
// req := client.R().
// SetBody("body").
// SetHeader("header", "value")
// clonedRequest := req.Clone(context.Background())
func (r *Request) Clone(ctx context.Context) *Request {
if ctx == nil {
panic("resty: Request.Clone nil context")
Expand Down

0 comments on commit 7cc8a14

Please sign in to comment.