diff --git a/README.md b/README.md index d24b91d..314850c 100644 --- a/README.md +++ b/README.md @@ -129,15 +129,19 @@ if err != nil { } ``` ### Make request with Go Context -Request with 5 seconds timeout: +Request Context lives in `fetch.Config` ```go -ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) -defer cancel() -_, err := fetch.Get[string]("https://petstore.swagger.io/v2/pet/1", fetch.Config{Ctx: ctx}) -if err != nil { - panic(err) +func myFuncWithContext(ctx context.Context) { + ... + res, err := fetch.Get[string]("https://petstore.swagger.io/v2/pet/1", fetch.Config{Ctx: ctx}) + ... } ``` +Request with 5 seconds timeout: +```go +fetch.Get[string]("https://petstore.swagger.io/v2/pet/1", fetch.Config{Timeout: 5*time.Second}) +``` + ### Request with headers ```go