forked from schwartzmx/gremgo-neptune
/
configuration.go
53 lines (45 loc) · 1.36 KB
/
configuration.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
package gremgo
import (
"crypto/tls"
"time"
)
// DialerConfig is the struct for defining configuration for WebSocket dialer
type DialerConfig func(*Ws)
// SetAuthentication sets on dialer credentials for authentication
func SetAuthentication(username string, password string) DialerConfig {
return func(c *Ws) {
c.auth = &auth{username: username, password: password}
}
}
// SetTimeout sets the dial timeout
func SetTimeout(seconds int) DialerConfig {
return func(c *Ws) {
c.timeout = time.Duration(seconds) * time.Second
}
}
// SetPingInterval sets the interval of ping sending for know is
// connection is alive and in consequence the client is connected
func SetPingInterval(seconds int) DialerConfig {
return func(c *Ws) {
c.pingInterval = time.Duration(seconds) * time.Second
}
}
// SetWritingWait sets the time for waiting that writing occur
func SetWritingWait(seconds int) DialerConfig {
return func(c *Ws) {
c.writingWait = time.Duration(seconds) * time.Second
}
}
// SetReadingWait sets the time for waiting that reading occur
func SetReadingWait(seconds int) DialerConfig {
return func(c *Ws) {
c.readingWait = time.Duration(seconds) * time.Second
}
}
// SetTLSClientConfig sets the TLS client config for the
// underlying websocket connection
func SetTLSClientConfig(conf *tls.Config) DialerConfig {
return func(c *Ws) {
c.tlsConfig = conf
}
}