Skip to content

Commit

Permalink
doc: godoc improvements and corrections (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Sep 12, 2024
1 parent e49dd06 commit aa7c48e
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 220 deletions.
209 changes: 81 additions & 128 deletions client.go

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ import (
)

var (
// Since v2.8.0
ErrAutoRedirectDisabled = errors.New("auto redirect is disabled")
)

type (
// RedirectPolicy to regulate the redirects in the resty client.
// Objects implementing the RedirectPolicy interface can be registered as
// Objects implementing the [RedirectPolicy] interface can be registered as
//
// Apply function should return nil to continue the redirect journey, otherwise
// return error to stop the redirect.
RedirectPolicy interface {
Apply(req *http.Request, via []*http.Request) error
}

// The RedirectPolicyFunc type is an adapter to allow the use of ordinary functions as RedirectPolicy.
// The [RedirectPolicyFunc] type is an adapter to allow the use of ordinary functions as [RedirectPolicy].
// If f is a function with the appropriate signature, RedirectPolicyFunc(f) is a RedirectPolicy object that calls f.
RedirectPolicyFunc func(*http.Request, []*http.Request) error
)
Expand Down
104 changes: 40 additions & 64 deletions request.go

Large diffs are not rendered by default.

15 changes: 5 additions & 10 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,19 @@ type Response struct {

// Body method returns HTTP response as []byte array for the executed request.
//
// Note: `Response.Body` might be nil, if `Request.SetOutput` is used.
// NOTE: [Response.Body] might be nil, if [Request.SetOutput] is used.
func (r *Response) Body() []byte {
if r.RawResponse == nil {
return []byte{}
}
return r.body
}

// SetBody method is to set Response body in byte slice. Typically,
// SetBody method is to set [Response] body in byte slice. Typically,
// its helpful for test cases.
//
// resp.SetBody([]byte("This is test body content"))
// resp.SetBody(nil)
//
// Since v2.10.0
func (r *Response) SetBody(b []byte) *Response {
r.body = b
return r
Expand Down Expand Up @@ -113,7 +111,7 @@ func (r *Response) String() string {

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

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

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Response Unexported methods
//_______________________________________________________________________

func (r *Response) setReceivedAt() {
r.receivedAt = time.Now()
if r.Request.clientTrace != nil {
Expand Down
2 changes: 1 addition & 1 deletion resty.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func New() *Client {
})
}

// NewWithClient method creates a new Resty client with given `http.Client`.
// NewWithClient method creates a new Resty client with given [http.Client].
func NewWithClient(hc *http.Client) *Client {
return createClient(hc)
}
Expand Down
2 changes: 1 addition & 1 deletion retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func RetryHooks(hooks []OnRetryFunc) Option {
}

// ResetMultipartReaders sets a boolean value which will lead the start being seeked out
// on all multipart file readers, if they implement io.ReadSeeker
// on all multipart file readers, if they implement [io.ReadSeeker]
func ResetMultipartReaders(value bool) Option {
return func(o *Options) {
o.resetReaders = value
Expand Down
8 changes: 7 additions & 1 deletion shellescape/shellescape.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// Copyright (c) 2015-present Jeevanandam M (jeeva@myjeeva.com)
// 2024 Ahuigo (https://github.com/ahuigo)
// All rights reserved.
// resty source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

/*
Package shellescape provides the shellescape.Quote to escape arbitrary
Package shellescape provides the methods to escape arbitrary
strings for a safe use as command line arguments in the most common
POSIX shells.
Expand Down
10 changes: 2 additions & 8 deletions trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (

// TraceInfo struct is used provide request trace info such as DNS lookup
// duration, Connection obtain duration, Server processing duration, etc.
//
// Since v2.0.0
type TraceInfo struct {
// DNSLookup is a duration that transport took to perform
// DNS lookup.
Expand Down Expand Up @@ -68,9 +66,9 @@ type TraceInfo struct {
// ClientTrace struct and its methods
//_______________________________________________________________________

// tracer struct maps the `httptrace.ClientTrace` hooks into Fields
// tracer struct maps the [httptrace.ClientTrace] hooks into Fields
// with same naming for easy understanding. Plus additional insights
// Request.
// [Request].
type clientTrace struct {
getConn time.Time
dnsStart time.Time
Expand All @@ -84,10 +82,6 @@ type clientTrace struct {
gotConnInfo httptrace.GotConnInfo
}

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Trace unexported methods
//_______________________________________________________________________

func (t *clientTrace) createContext(ctx context.Context) context.Context {
return httptrace.WithClientTrace(
ctx,
Expand Down
4 changes: 0 additions & 4 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ type ResponseLog struct {
Body string
}

//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Package Unexported methods
//_______________________________________________________________________

// way to disable the HTML escape as opt-in
func jsonMarshal(c *Client, r *Request, d interface{}) (*bytes.Buffer, error) {
if !r.jsonEscapeHTML || !c.jsonEscapeHTML {
Expand Down

0 comments on commit aa7c48e

Please sign in to comment.