Skip to content

Commit

Permalink
refactor(rest): simplify default client do method & example
Browse files Browse the repository at this point in the history
Signed-off-by: lvlcn-t <[email protected]>
  • Loading branch information
lvlcn-t committed Sep 26, 2024
1 parent 58e172a commit abae869
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions example/rest/simple/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func main() {
time.Sleep(time.Second)

// Make an API call to the server
makeAPICall(ctx)
callAPI(ctx)

// Shutdown the server
err = srv.Shutdown(ctx)
Expand All @@ -59,8 +59,8 @@ func main() {
}
}

// makeAPICall makes an API call to the server
func makeAPICall(ctx context.Context) {
// callAPI makes an API call to the server
func callAPI(ctx context.Context) {
// Create a new REST endpoint
endpoint := rest.Get("http://localhost:8080")

Expand Down
4 changes: 2 additions & 2 deletions rest/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ var DefaultTransport = defaultTransport()
// The request will be made to "https://api.example.com/resource" with the payload marshaled to JSON
// and the response unmarshaled into a response object with the given type.
func Do[T any](ctx context.Context, endpoint *Endpoint, payload any, opts ...RequestOption) (resp T, code int, err error) {
status, err := DefaultClient.Do(ctx, endpoint, payload, &resp, opts...)
return resp, status, err
code, err = DefaultClient.Do(ctx, endpoint, payload, &resp, opts...)
return resp, code, err
}

// Close closes the default rest client and gracefully awaits all pending requests to finish.
Expand Down

0 comments on commit abae869

Please sign in to comment.