Skip to content

Commit 9390194

Browse files
authored
docs: godoc update (#957)
1 parent cffb5b6 commit 9390194

File tree

5 files changed

+103
-84
lines changed

5 files changed

+103
-84
lines changed

client.go

+55-57
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ func (c *Client) SetAuthScheme(scheme string) *Client {
602602
//
603603
// NOTE:
604604
// - On the QOP `auth-int` scenario, the request body is read into memory to
605-
// compute the body hash that consumes additional memory usage.
606-
// - It is recommended to create a dedicated client instance for digest auth,
605+
// compute the body hash that increases memory usage.
606+
// - Create a dedicated client instance to use digest auth,
607607
// as it does digest auth for all the requests raised by the client.
608608
//
609609
// [RFC 7616]: https://datatracker.ietf.org/doc/html/rfc7616
@@ -676,16 +676,12 @@ func (c *Client) NewRequest() *Request {
676676
// SetRequestMiddlewares method allows Resty users to override the default request
677677
// middlewares sequence
678678
//
679-
// client := New()
680-
// defer client.Close()
681-
//
682679
// client.SetRequestMiddlewares(
683-
// CustomRequest1Middleware,
684-
// CustomRequest2Middleware,
685-
// resty.PrepareRequestMiddleware, // after this, Request.RawRequest is available
686-
// resty.GenerateCurlRequestMiddleware,
687-
// CustomRequest3Middleware,
688-
// CustomRequest4Middleware,
680+
// Custom1RequestMiddleware,
681+
// Custom2RequestMiddleware,
682+
// resty.PrepareRequestMiddleware, // after this, `Request.RawRequest` instance is available
683+
// Custom3RequestMiddleware,
684+
// Custom4RequestMiddleware,
689685
// )
690686
//
691687
// See, [Client.AddRequestMiddleware]
@@ -703,23 +699,20 @@ func (c *Client) SetRequestMiddlewares(middlewares ...RequestMiddleware) *Client
703699
// SetResponseMiddlewares method allows Resty users to override the default response
704700
// middlewares sequence
705701
//
706-
// client := New()
707-
// defer client.Close()
708-
//
709702
// client.SetResponseMiddlewares(
710-
// CustomResponse1Middleware,
711-
// CustomResponse2Middleware,
712-
// resty.AutoParseResponseMiddleware, // before this, body is not read except on debug flow
713-
// CustomResponse3Middleware,
714-
// resty.SaveToFileResponseMiddleware, // See, Request.SetOutputFile
715-
// CustomResponse4Middleware,
716-
// CustomResponse5Middleware,
703+
// Custom1ResponseMiddleware,
704+
// Custom2ResponseMiddleware,
705+
// resty.AutoParseResponseMiddleware, // before this, the body is not read except on the debug flow
706+
// Custom3ResponseMiddleware,
707+
// resty.SaveToFileResponseMiddleware, // See, Request.SetOutputFileName, Request.SetSaveResponse
708+
// Custom4ResponseMiddleware,
709+
// Custom5ResponseMiddleware,
717710
// )
718711
//
719712
// See, [Client.AddResponseMiddleware]
720713
//
721714
// NOTE:
722-
// - It overwrites the existing request middleware list.
715+
// - It overwrites the existing response middleware list.
723716
// - Be sure to include Resty response middlewares in the response chain at the appropriate spot.
724717
func (c *Client) SetResponseMiddlewares(middlewares ...ResponseMiddleware) *Client {
725718
c.lock.Lock()
@@ -1167,7 +1160,7 @@ func (c *Client) Timeout() time.Duration {
11671160
//
11681161
// It can be overridden at the request level. See [Request.SetTimeout]
11691162
//
1170-
// NOTE: Resty uses [context.WithTimeout] on the request, it does not use [http.Client.Timeout]
1163+
// NOTE: Resty uses [context.WithTimeout] on the request, it does not use [http.Client].Timeout
11711164
func (c *Client) SetTimeout(timeout time.Duration) *Client {
11721165
c.lock.Lock()
11731166
defer c.lock.Unlock()
@@ -1242,7 +1235,7 @@ func (c *Client) RetryCount() int {
12421235
// See [Request.SetRetryStrategy]
12431236
//
12441237
// NOTE:
1245-
// - By default, Resty only does retry on idempotent HTTP methods, [RFC 9110 Section 9.2.2], [RFC 9110 Section 18.2]
1238+
// - By default, Resty only does retry on idempotent HTTP verb, [RFC 9110 Section 9.2.2], [RFC 9110 Section 18.2]
12461239
//
12471240
// [RFC 9110 Section 9.2.2]: https://datatracker.ietf.org/doc/html/rfc9110.html#name-idempotent-methods
12481241
// [RFC 9110 Section 18.2]: https://datatracker.ietf.org/doc/html/rfc9110.html#name-method-registration
@@ -1380,8 +1373,9 @@ func (c *Client) RetryConditions() []RetryConditionFunc {
13801373
// The request will retry if any functions return `true`, otherwise return `false`.
13811374
//
13821375
// NOTE:
1376+
// - The default retry conditions are applied first.
13831377
// - The client-level retry conditions are applied to all requests.
1384-
// - The request-level retry conditions are executed first before client-level
1378+
// - The request-level retry conditions are executed first before the client-level
13851379
// retry conditions. See [Request.AddRetryConditions], [Request.SetRetryConditions]
13861380
func (c *Client) AddRetryConditions(conditions ...RetryConditionFunc) *Client {
13871381
c.lock.Lock()
@@ -1422,13 +1416,12 @@ func (c *Client) TLSClientConfig() *tls.Config {
14221416

14231417
// SetTLSClientConfig method sets TLSClientConfig for underlying client Transport.
14241418
//
1425-
// For Example:
1426-
//
1427-
// // One can set a custom root certificate. Refer: http://golang.org/pkg/crypto/tls/#example_Dial
1428-
// client.SetTLSClientConfig(&tls.Config{ RootCAs: roots })
1419+
// Values supported by https://pkg.go.dev/crypto/tls#Config can be configured.
14291420
//
1430-
// // or One can disable security check (https)
1431-
// client.SetTLSClientConfig(&tls.Config{ InsecureSkipVerify: true })
1421+
// // Disable SSL cert verification for local development
1422+
// client.SetTLSClientConfig(&tls.Config{
1423+
// InsecureSkipVerify: true
1424+
// })
14321425
//
14331426
// NOTE: This method overwrites existing [http.Transport.TLSClientConfig]
14341427
func (c *Client) SetTLSClientConfig(tlsConfig *tls.Config) *Client {
@@ -1507,7 +1500,7 @@ func (c *Client) RemoveProxy() *Client {
15071500
return c
15081501
}
15091502

1510-
// SetCertificateFromString method helps to set client certificates into Resty
1503+
// SetCertificateFromFile method helps to set client certificates into Resty
15111504
// from cert and key files to perform SSL client authentication
15121505
//
15131506
// client.SetCertificateFromFile("certs/client.pem", "certs/client.key")
@@ -1543,8 +1536,8 @@ func (c *Client) SetCertificateFromString(certStr, certKeyStr string) *Client {
15431536
return c
15441537
}
15451538

1546-
// SetCertificates method helps to conveniently set client certificates into Resty
1547-
// to perform SSL client authentication
1539+
// SetCertificates method helps to conveniently set a slice of client certificates
1540+
// into Resty to perform SSL client authentication
15481541
//
15491542
// cert, err := tls.LoadX509KeyPair("certs/client.pem", "certs/client.key")
15501543
// if err != nil {
@@ -1566,7 +1559,8 @@ func (c *Client) SetCertificates(certs ...tls.Certificate) *Client {
15661559
return c
15671560
}
15681561

1569-
// SetRootCertificates method helps to add one or more root certificates into the Resty client
1562+
// SetRootCertificates method helps to add one or more root certificate files
1563+
// into the Resty client
15701564
//
15711565
// // one pem file path
15721566
// client.SetRootCertificates("/path/to/root/pemFile.pem")
@@ -1592,14 +1586,14 @@ func (c *Client) SetRootCertificates(pemFilePaths ...string) *Client {
15921586
return c
15931587
}
15941588

1595-
// SetRootCertificatesWatcher method enables dynamic reloading of one or more root certificates.
1589+
// SetRootCertificatesWatcher method enables dynamic reloading of one or more root certificate files.
15961590
// It is designed for scenarios involving long-running Resty clients where certificates may be renewed.
15971591
//
15981592
// client.SetRootCertificatesWatcher(
15991593
// &resty.CertWatcherOptions{
16001594
// PoolInterval: 24 * time.Hour,
16011595
// },
1602-
// "root-ca.crt",
1596+
// "root-ca.pem",
16031597
// )
16041598
func (c *Client) SetRootCertificatesWatcher(options *CertWatcherOptions, pemFilePaths ...string) *Client {
16051599
c.SetRootCertificates(pemFilePaths...)
@@ -1609,7 +1603,7 @@ func (c *Client) SetRootCertificatesWatcher(options *CertWatcherOptions, pemFile
16091603
return c
16101604
}
16111605

1612-
// SetRootCertificateFromString method helps to add one or more root certificates
1606+
// SetRootCertificateFromString method helps to add root certificate from the string
16131607
// into the Resty client
16141608
//
16151609
// myRootCertStr := `-----BEGIN CERTIFICATE-----
@@ -1622,21 +1616,21 @@ func (c *Client) SetRootCertificateFromString(pemCerts string) *Client {
16221616
return c
16231617
}
16241618

1625-
// SetClientRootCertificates method helps to add one or more client's root
1626-
// certificates into the Resty client
1619+
// SetClientRootCertificates method helps to add one or more client root
1620+
// certificate files into the Resty client
16271621
//
16281622
// // one pem file path
1629-
// client.SetClientCertificates("/path/to/client/pemFile.pem")
1623+
// client.SetClientRootCertificates("/path/to/client-root/pemFile.pem")
16301624
//
16311625
// // one or more pem file path(s)
1632-
// client.SetClientCertificates(
1633-
// "/path/to/client/pemFile1.pem",
1634-
// "/path/to/client/pemFile2.pem"
1635-
// "/path/to/client/pemFile3.pem"
1626+
// client.SetClientRootCertificates(
1627+
// "/path/to/client-root/pemFile1.pem",
1628+
// "/path/to/client-root/pemFile2.pem"
1629+
// "/path/to/client-root/pemFile3.pem"
16361630
// )
16371631
//
16381632
// // if you happen to have string slices
1639-
// client.SetClientCertificates(certs...)
1633+
// client.SetClientRootCertificates(certs...)
16401634
func (c *Client) SetClientRootCertificates(pemFilePaths ...string) *Client {
16411635
for _, fp := range pemFilePaths {
16421636
pemData, err := os.ReadFile(fp)
@@ -1649,14 +1643,14 @@ func (c *Client) SetClientRootCertificates(pemFilePaths ...string) *Client {
16491643
return c
16501644
}
16511645

1652-
// SetClientRootCertificatesWatcher method enables dynamic reloading of one or more client root certificates.
1646+
// SetClientRootCertificatesWatcher method enables dynamic reloading of one or more client root certificate files.
16531647
// It is designed for scenarios involving long-running Resty clients where certificates may be renewed.
16541648
//
16551649
// client.SetClientRootCertificatesWatcher(
16561650
// &resty.CertWatcherOptions{
16571651
// PoolInterval: 24 * time.Hour,
16581652
// },
1659-
// "root-ca.crt",
1653+
// "client-root-ca.pem",
16601654
// )
16611655
func (c *Client) SetClientRootCertificatesWatcher(options *CertWatcherOptions, pemFilePaths ...string) *Client {
16621656
c.SetClientRootCertificates(pemFilePaths...)
@@ -1666,8 +1660,8 @@ func (c *Client) SetClientRootCertificatesWatcher(options *CertWatcherOptions, p
16661660
return c
16671661
}
16681662

1669-
// SetClientRootCertificateFromString method helps to add one or more clients
1670-
// root certificates into the Resty client
1663+
// SetClientRootCertificateFromString method helps to add a client root certificate
1664+
// from the string into the Resty client
16711665
//
16721666
// myClientRootCertStr := `-----BEGIN CERTIFICATE-----
16731667
// ... cert content ...
@@ -1878,12 +1872,13 @@ func (c *Client) SetCloseConnection(close bool) *Client {
18781872
}
18791873

18801874
// SetDoNotParseResponse method instructs Resty not to parse the response body automatically.
1875+
//
18811876
// Resty exposes the raw response body as [io.ReadCloser]. If you use it, do not
18821877
// forget to close the body, otherwise, you might get into connection leaks, and connection
18831878
// reuse may not happen.
18841879
//
1885-
// NOTE: [Response] middlewares are not executed using this option. You have
1886-
// taken over the control of response parsing from Resty.
1880+
// NOTE: The default [Response] middlewares are not executed when using this option. User
1881+
// takes over the control of handling response body from Resty.
18871882
func (c *Client) SetDoNotParseResponse(notParse bool) *Client {
18881883
c.lock.Lock()
18891884
defer c.lock.Unlock()
@@ -2074,7 +2069,8 @@ func (c *Client) SetTrace(t bool) *Client {
20742069
// client instance level.
20752070
//
20762071
// By default, Resty does not log the curl command in the debug log since it has the potential
2077-
// to leak sensitive data unless explicitly enabled via [Client.SetDebugLogCurlCmd].
2072+
// to leak sensitive data unless explicitly enabled via [Client.SetDebugLogCurlCmd] or
2073+
// [Request.SetDebugLogCurlCmd].
20782074
//
20792075
// NOTE: Use with care.
20802076
// - Potential to leak sensitive data from [Request] and [Response] in the debug log
@@ -2097,7 +2093,8 @@ func (c *Client) DisableGenerateCurlCmd() *Client {
20972093
// client instance level.
20982094
//
20992095
// By default, Resty does not log the curl command in the debug log since it has the potential
2100-
// to leak sensitive data unless explicitly enabled via [Client.SetDebugLogCurlCmd].
2096+
// to leak sensitive data unless explicitly enabled via [Client.SetDebugLogCurlCmd] or
2097+
// [Request.SetDebugLogCurlCmd].
21012098
//
21022099
// NOTE: Use with care.
21032100
// - Potential to leak sensitive data from [Request] and [Response] in the debug log
@@ -2143,7 +2140,7 @@ func (c *Client) ResponseBodyUnlimitedReads() bool {
21432140
return c.resBodyUnlimitedReads
21442141
}
21452142

2146-
// SetResponseBodyUnlimitedReads method is to turn on/off the response body copy
2143+
// SetResponseBodyUnlimitedReads method is to turn on/off the response body in memory
21472144
// that provides an ability to do unlimited reads.
21482145
//
21492146
// It can be overridden at the request level; see [Request.SetResponseBodyUnlimitedReads]
@@ -2152,7 +2149,7 @@ func (c *Client) ResponseBodyUnlimitedReads() bool {
21522149
// - When debug mode is enabled
21532150
//
21542151
// NOTE: Use with care
2155-
// - Turning on this feature uses additional memory to store a copy of the response body buffer.
2152+
// - Turning on this feature keeps the response body in memory, which might cause additional memory usage.
21562153
func (c *Client) SetResponseBodyUnlimitedReads(b bool) *Client {
21572154
c.lock.Lock()
21582155
defer c.lock.Unlock()
@@ -2179,7 +2176,8 @@ func (c *Client) Client() *http.Client {
21792176
// - Interface values are not deeply cloned. Thus, both the original and the
21802177
// clone will use the same value.
21812178
// - It is not safe for concurrent use. You should only use this method
2182-
// when you are sure that any other concurrent process is not using the client.
2179+
// when you are sure that any other concurrent process is not using the client
2180+
// or client instance is protected by a mutex.
21832181
func (c *Client) Clone(ctx context.Context) *Client {
21842182
cc := new(Client)
21852183
// dereference the pointer and copy the value

multipart.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ type MultipartField struct {
4949
// ProgressCallback function is used to provide live progress details
5050
// during a multipart upload (Optional)
5151
//
52-
// NOTE: It is recommended to set the FileSize value when using
53-
// ProgressCallback feature so that Resty sends the FileSize
52+
// NOTE: It is recommended to set the FileSize value when using `MultipartField.Reader`
53+
// with `ProgressCallback` feature so that Resty sends the FileSize
5454
// value via [MultipartFieldProgress]
5555
ProgressCallback MultipartFieldCallbackFunc
5656

0 commit comments

Comments
 (0)