diff options
| author | Adnan Maolood <[email protected]> | 2021-02-23 15:55:27 -0500 |
|---|---|---|
| committer | Adnan Maolood <[email protected]> | 2021-02-23 15:56:44 -0500 |
| commit | 31e16d5a4c8a00134f49f9bc176b243bc175303f (patch) | |
| tree | 95b861dfc1adfcb4cd3cce5e7c23ed4b22dcec5d /examples | |
| parent | client: Cancel context on IO errors (diff) | |
| download | go-gemini-31e16d5a4c8a00134f49f9bc176b243bc175303f.tar.xz go-gemini-31e16d5a4c8a00134f49f9bc176b243bc175303f.zip | |
examples/client: Stream response body
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/client.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/examples/client.go b/examples/client.go index c806a8f..6a4a848 100644 --- a/examples/client.go +++ b/examples/client.go @@ -97,7 +97,8 @@ func do(req *gemini.Request, via []*gemini.Request) (*gemini.Response, error) { client := gemini.Client{ TrustCertificate: trustCertificate, } - resp, err := client.Do(context.Background(), req) + ctx := context.Background() + resp, err := client.Do(ctx, req) if err != nil { return resp, err } @@ -156,11 +157,10 @@ func main() { // Handle response if resp.Status.Class() == gemini.StatusSuccess { - body, err := io.ReadAll(resp.Body) + _, err := io.Copy(os.Stdout, resp.Body) if err != nil { log.Fatal(err) } - fmt.Print(string(body)) } else { fmt.Printf("%d %s\n", resp.Status, resp.Meta) os.Exit(1) |