Repository navigation
v0.7.0
Changelog
- c1ac40e refactor: ♻️ undeprecate WithTimeout but do not use default timeout
By default requests with a rip client will not time out. Passing rip.WithTimeout(...) to rip.NewClient will add a timeout to requests. Additional you can have requests time out using context timeouts. If a timeout on the client is set, whichever timeout value is lower (context/WithTimeout) will be used.
// no timeout at all
c, err := rip.NewClient(
host,
rip.WithDefaultHeaders(rip.Header{"x-api-key": os.Getenv("API_KEY_BLOGAPI")}),
)
[...]
// timeout via option
c, err := rip.NewClient(
host,
rip.WithDefaultHeaders(rip.Header{"x-api-key": os.Getenv("API_KEY_BLOGAPI")}),
rip.WithTimeout(1*time.Millisecond)
)
resp, err := c.NR().Execute(ctx.Background(), "GET", "/test")
if err != nil {
panic()
}
defer resp.Close()
[...]
// >> "https://dummyjson.com/test": context deadline exceeded
// timeout via ctx
c, err := rip.NewClient(
"https://dummyjson.com",
rip.WithDefaultHeaders(rip.Header{"x-api-key": os.Getenv("API_KEY_BLOGAPI")}),
)
[...]
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Millisecond)
defer cancel()
resp, err := c.NR().Execute(ctx, "GET", "/test")
if err != nil {
panic()
}
defer resp.Close()
// >> "https://dummyjson.com/test": context deadline exceeded