aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2021-02-21 00:20:42 -0500
committerAdnan Maolood <[email protected]>2021-02-21 00:20:42 -0500
commit0c8c945ebaefd25197c20a239c6866ed748bd762 (patch)
treedad477beadf7027dd5a9a8a7d7bdfcaf272e6484 /client.go
parentserver: Add Context field (diff)
downloadgo-gemini-0c8c945ebaefd25197c20a239c6866ed748bd762.tar.xz
go-gemini-0c8c945ebaefd25197c20a239c6866ed748bd762.zip
client: Inline result type
Diffstat (limited to 'client.go')
-rw-r--r--client.go21
1 files changed, 11 insertions, 10 deletions
diff --git a/client.go b/client.go
index 5a94031..d534fbe 100644
--- a/client.go
+++ b/client.go
@@ -125,9 +125,15 @@ func (c *Client) Do(ctx context.Context, req *Request) (*Response, error) {
ServerName: host,
})
+ type result struct {
+ resp *Response
+ err error
+ }
+
res := make(chan result, 1)
go func() {
- res <- c.do(conn, req)
+ resp, err := c.do(conn, req)
+ res <- result{resp, err}
}()
select {
@@ -139,21 +145,16 @@ func (c *Client) Do(ctx context.Context, req *Request) (*Response, error) {
}
}
-type result struct {
- resp *Response
- err error
-}
-
-func (c *Client) do(conn net.Conn, req *Request) result {
+func (c *Client) do(conn net.Conn, req *Request) (*Response, error) {
// Write the request
if err := req.Write(conn); err != nil {
- return result{nil, err}
+ return nil, err
}
// Read the response
resp, err := ReadResponse(conn)
if err != nil {
- return result{nil, err}
+ return nil, err
}
// Store TLS connection state
@@ -162,7 +163,7 @@ func (c *Client) do(conn net.Conn, req *Request) result {
resp.TLS = &state
}
- return result{resp, nil}
+ return resp, nil
}
func (c *Client) dialContext(ctx context.Context, network, addr string) (net.Conn, error) {