Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
glossd committed Dec 16, 2024
1 parent 31e6b9f commit 7da6192
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7da6192

Please sign in to comment.