Skip to content

Wrong documentation on NewClient #564

Open
@levanidev

Description

@levanidev

Documentation of NewClient states:

// The returned client is not valid beyond the lifetime of the context.

However, even if you pass a canceled context into NewClient, it has absolutely no effect.
For example:

func (c *Config) NewCustomClient(ctx context.Context) *http.Client {

    ctx2, cancel := context.WithCancel(ctx)
    cancel()
    return oauth2.NewClient(ctx2, c.TokenSource(ctx))
}

and then make request with returned client:

c := cfg.NewCustomClient(context.Background())
req, _ := http.NewRequest(http.MethodGet, getURL().String(), http.NoBody)
req.Header.Set("Accept", "application/json")
resp, err := c.Do(req)

it has no effect.

or am I misunderstanding something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions