forked from ssdb/gossdb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoption.go
60 lines (51 loc) · 1.12 KB
/
option.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
package ssdb
import (
"net"
"net/url"
"time"
)
// Option is a function that configures a Client
type Option func(c *Client)
// URL ssdb://127.0.0.1:8888[?Auth=password]
func URL(u string) Option {
uu, _ := url.Parse(u)
return func(c *Client) {
c.addr = uu.Host
c.auth = uu.Query().Get("Auth")
}
}
// Addr 127.0.0.1:8888
func Addr(addr string) Option {
return func(c *Client) {
c.addr = addr
}
}
// Auth password
func Auth(auth string) Option {
return func(c *Client) {
c.auth = auth
}
}
// DialHandler proxy
func DialHandler(df func(addr string) (net.Conn, error)) Option {
return func(c *Client) {
c.dialHandler = df
}
}
func DialTimeoutOption(connectTimeout time.Duration) Option {
return func(c *Client) {
c.dialHandler = func(addr string) (conn net.Conn, e error) {
return net.DialTimeout("tcp", addr, connectTimeout)
}
}
}
func ReadWriteTimeoutOption(readWriteTimeout time.Duration) Option {
return func(c *Client) {
c.readWriteTimeout = readWriteTimeout
}
}
func IgnoreNotFoundError(ignoreNotFoundError bool) Option {
return func(c *Client) {
c.ignoreNotFoundError = ignoreNotFoundError
}
}