-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
94 lines (84 loc) · 1.58 KB
/
client.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package finger
import (
"net"
)
// A Client is a finger-protocol client.
//
// It handles sending a finger-protocol client request and receiving a finger-protocol server response.
//
// var address finger.Address = finger.CreateAddress("example.com", 79)
//
// // ...
//
// var conn net.Conn
//
// conn, err = net.Dial("tcp", address.Resolve())
//
// // ...
//
// var client finger.Client = finger.AssembleClient(conn)
//
// // ...
//
// var request finger.Request = finger.SomeRequestTarget("joeblow")
//
// // ...
//
// responseReader, err := client.Do(request)
//
// // ...
//
// io.Copy(os.Stdout, response)
type Client struct {
conn net.Conn
}
// AssebleClient returns a client that communicates over a net.Conn.
//
// Example
//
// var conn net.Conn
//
// // ...
//
// var fingerClient finger.Client = finger.AssembleClient(conn)
func AssembleClient(conn net.Conn) Client {
return Client{
conn:conn,
}
}
// Close closes the wrapped net.Conn.
func (receiver *Client) Close() error {
if nil == receiver {
return nil
}
var conn net.Conn
{
conn = receiver.conn
if nil == conn {
return nil
}
}
return conn.Close()
}
// LocalAddr returns the local-address of the connection, if known.
func (receiver Client) LocalAddr() net.Addr {
var conn net.Conn
{
conn = receiver.conn
if nil == conn {
return nil
}
}
return conn.LocalAddr()
}
// RemoteAddr returns the remote-address of the connection, if known.
func (receiver Client) RemoteAddr() net.Addr {
var conn net.Conn
{
conn = receiver.conn
if nil == conn {
return nil
}
}
return conn.RemoteAddr()
}