-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
42 lines (35 loc) · 983 Bytes
/
Copy pathexample_test.go
File metadata and controls
42 lines (35 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (c) 2026 dexpace and Omar Aljarrah.
// Licensed under the MIT License. See LICENSE in the repository root for details.
package dexpace_test
import (
"context"
"fmt"
"io"
"net/http"
"net/http/httptest"
dexpace "github.com/dexpace/go-sdk"
"github.com/dexpace/go-sdk/retry"
)
// ExampleClient_Do shows the smallest end-to-end use: build a client, send a
// standard *http.Request, read the response.
func ExampleClient_Do() {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
_, _ = fmt.Fprint(w, "pong")
}))
defer srv.Close()
client := dexpace.New(
dexpace.WithRetry(retry.Options{MaxRetries: 2}),
)
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, srv.URL, nil)
if err != nil {
panic(err)
}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer func() { _ = resp.Body.Close() }()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
// Output: pong
}