Skip to content

Commit

Permalink
Update xhttp
Browse files Browse the repository at this point in the history
  • Loading branch information
onanying committed May 22, 2024
1 parent e72c3d4 commit 4754e1d
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/xhttp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ xhttp.DefaultOptions.DebugFunc = func(l *Log) {
f := func(l *Log) {
log.Println(l)
}
xhttp.Request("POST", url, xhttp.WithDebugFunc(f))
xhttp.NewRequest("POST", url, xhttp.WithDebugFunc(f))
```

The log object contains the following fields
Expand Down Expand Up @@ -73,7 +73,7 @@ retryIf := func(resp *xhttp.Response, err error) error {
}
return nil
}
resp, err := xhttp.Request("GET", url, xhttp.WithRetry(retryIf, retry.Attempts(2)))
resp, err := xhttp.NewRequest("GET", url, xhttp.WithRetry(retryIf, retry.Attempts(2)))
```

Network error, no retry.
Expand All @@ -89,7 +89,7 @@ retryIf := func(resp *xhttp.Response, err error) error {
}
return nil
}
resp, err := xhttp.Request("GET", url, xhttp.WithRetry(retryIf, retry.Attempts(2)))
resp, err := xhttp.NewRequest("GET", url, xhttp.WithRetry(retryIf, retry.Attempts(2)))
```

## Middlewares
Expand All @@ -114,6 +114,19 @@ logicMiddleware := func(next xhttp.HandlerFunc) xhttp.HandlerFunc {
resp, err := xhttp.NewRequest("GET", "https://github.com/", xhttp.WithMiddlewares(logicMiddleware))
```

## Shutdown

Before shutdown, all requests will be completed and work with middleware to save the response results to the database.

```go
ch := make(chan os.Signal)
signal.Notify(ch, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-ch
xhttp.Shutdown()
}()
```

## License

Apache License Version 2.0, http://www.apache.org/licenses/

0 comments on commit 4754e1d

Please sign in to comment.