Skip to content

Commit aa7c48e

Browse files
authored
doc: godoc improvements and corrections (#849)
1 parent e49dd06 commit aa7c48e

File tree

9 files changed

+139
-220
lines changed

9 files changed

+139
-220
lines changed

client.go

+81-128
Large diffs are not rendered by default.

redirect.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,20 @@ import (
1313
)
1414

1515
var (
16-
// Since v2.8.0
1716
ErrAutoRedirectDisabled = errors.New("auto redirect is disabled")
1817
)
1918

2019
type (
2120
// RedirectPolicy to regulate the redirects in the resty client.
22-
// Objects implementing the RedirectPolicy interface can be registered as
21+
// Objects implementing the [RedirectPolicy] interface can be registered as
2322
//
2423
// Apply function should return nil to continue the redirect journey, otherwise
2524
// return error to stop the redirect.
2625
RedirectPolicy interface {
2726
Apply(req *http.Request, via []*http.Request) error
2827
}
2928

30-
// The RedirectPolicyFunc type is an adapter to allow the use of ordinary functions as RedirectPolicy.
29+
// The [RedirectPolicyFunc] type is an adapter to allow the use of ordinary functions as [RedirectPolicy].
3130
// If f is a function with the appropriate signature, RedirectPolicyFunc(f) is a RedirectPolicy object that calls f.
3231
RedirectPolicyFunc func(*http.Request, []*http.Request) error
3332
)

request.go

+40-64
Large diffs are not rendered by default.

response.go

+5-10
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,19 @@ type Response struct {
2929

3030
// Body method returns HTTP response as []byte array for the executed request.
3131
//
32-
// Note: `Response.Body` might be nil, if `Request.SetOutput` is used.
32+
// NOTE: [Response.Body] might be nil, if [Request.SetOutput] is used.
3333
func (r *Response) Body() []byte {
3434
if r.RawResponse == nil {
3535
return []byte{}
3636
}
3737
return r.body
3838
}
3939

40-
// SetBody method is to set Response body in byte slice. Typically,
40+
// SetBody method is to set [Response] body in byte slice. Typically,
4141
// its helpful for test cases.
4242
//
4343
// resp.SetBody([]byte("This is test body content"))
4444
// resp.SetBody(nil)
45-
//
46-
// Since v2.10.0
4745
func (r *Response) SetBody(b []byte) *Response {
4846
r.body = b
4947
return r
@@ -113,7 +111,7 @@ func (r *Response) String() string {
113111

114112
// Time method returns the time of HTTP response time that from request we sent and received a request.
115113
//
116-
// See `Response.ReceivedAt` to know when client received response and see `Response.Request.Time` to know
114+
// See [Response.ReceivedAt] to know when client received response and see `Response.Request.Time` to know
117115
// when client sent a request.
118116
func (r *Response) Time() time.Duration {
119117
if r.Request.clientTrace != nil {
@@ -134,7 +132,8 @@ func (r *Response) Size() int64 {
134132
return r.size
135133
}
136134

137-
// RawBody method exposes the HTTP raw response body. Use this method in-conjunction with `SetDoNotParseResponse`
135+
// RawBody method exposes the HTTP raw response body. Use this method in-conjunction with
136+
// [Client.SetDoNotParseResponse] or [Request.SetDoNotParseResponse]
138137
// option otherwise you get an error as `read err: http: read on closed response body`.
139138
//
140139
// Do not forget to close the body, otherwise you might get into connection leaks, no connection reuse.
@@ -156,10 +155,6 @@ func (r *Response) IsError() bool {
156155
return r.StatusCode() > 399
157156
}
158157

159-
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
160-
// Response Unexported methods
161-
//_______________________________________________________________________
162-
163158
func (r *Response) setReceivedAt() {
164159
r.receivedAt = time.Now()
165160
if r.Request.clientTrace != nil {

resty.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func New() *Client {
2424
})
2525
}
2626

27-
// NewWithClient method creates a new Resty client with given `http.Client`.
27+
// NewWithClient method creates a new Resty client with given [http.Client].
2828
func NewWithClient(hc *http.Client) *Client {
2929
return createClient(hc)
3030
}

retry.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func RetryHooks(hooks []OnRetryFunc) Option {
8484
}
8585

8686
// ResetMultipartReaders sets a boolean value which will lead the start being seeked out
87-
// on all multipart file readers, if they implement io.ReadSeeker
87+
// on all multipart file readers, if they implement [io.ReadSeeker]
8888
func ResetMultipartReaders(value bool) Option {
8989
return func(o *Options) {
9090
o.resetReaders = value

shellescape/shellescape.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
// Copyright (c) 2015-present Jeevanandam M ([email protected])
2+
// 2024 Ahuigo (https://github.com/ahuigo)
3+
// All rights reserved.
4+
// resty source code and usage is governed by a MIT style
5+
// license that can be found in the LICENSE file.
6+
17
/*
2-
Package shellescape provides the shellescape.Quote to escape arbitrary
8+
Package shellescape provides the methods to escape arbitrary
39
strings for a safe use as command line arguments in the most common
410
POSIX shells.
511

trace.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import (
1818

1919
// TraceInfo struct is used provide request trace info such as DNS lookup
2020
// duration, Connection obtain duration, Server processing duration, etc.
21-
//
22-
// Since v2.0.0
2321
type TraceInfo struct {
2422
// DNSLookup is a duration that transport took to perform
2523
// DNS lookup.
@@ -68,9 +66,9 @@ type TraceInfo struct {
6866
// ClientTrace struct and its methods
6967
//_______________________________________________________________________
7068

71-
// tracer struct maps the `httptrace.ClientTrace` hooks into Fields
69+
// tracer struct maps the [httptrace.ClientTrace] hooks into Fields
7270
// with same naming for easy understanding. Plus additional insights
73-
// Request.
71+
// [Request].
7472
type clientTrace struct {
7573
getConn time.Time
7674
dnsStart time.Time
@@ -84,10 +82,6 @@ type clientTrace struct {
8482
gotConnInfo httptrace.GotConnInfo
8583
}
8684

87-
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
88-
// Trace unexported methods
89-
//_______________________________________________________________________
90-
9185
func (t *clientTrace) createContext(ctx context.Context) context.Context {
9286
return httptrace.WithClientTrace(
9387
ctx,

util.go

-4
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@ type ResponseLog struct {
145145
Body string
146146
}
147147

148-
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
149-
// Package Unexported methods
150-
//_______________________________________________________________________
151-
152148
// way to disable the HTML escape as opt-in
153149
func jsonMarshal(c *Client, r *Request, d interface{}) (*bytes.Buffer, error) {
154150
if !r.jsonEscapeHTML || !c.jsonEscapeHTML {

0 commit comments

Comments
 (0)