-
Notifications
You must be signed in to change notification settings - Fork 1
/
configuration.go
60 lines (49 loc) · 1.63 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
54
55
56
57
58
59
60
package gremgoser
import (
"time"
"github.com/google/uuid"
"github.com/intwinelabs/logger"
)
// NewClientConfig returns a default client config
func NewClientConfig(uri string) *ClientConfig {
return &ClientConfig{
URI: uri,
Timeout: 300 * time.Second,
PingInterval: 60 * time.Second,
WritingWait: 120 * time.Second,
ReadingWait: 120 * time.Second,
}
}
// SetAuthentication sets on dialer credentials for authentication
func (conf *ClientConfig) SetAuthentication(username string, password string) {
conf.AuthReq = prepareAuthRequest(uuid.New(), username, password)
}
// SetDebug sets the debug flag
func (conf *ClientConfig) SetDebug() {
conf.Debug = true
}
// SetVerbose sets the verbose flag
func (conf *ClientConfig) SetVerbose() {
conf.Verbose = true
}
// SetTimeout sets the dial timeout
func (conf *ClientConfig) SetTimeout(seconds int) {
conf.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 (conf *ClientConfig) SetPingInterval(seconds int) {
conf.PingInterval = time.Duration(seconds) * time.Second
}
// SetWritingWait sets the time for waiting that writing occur
func (conf *ClientConfig) SetWritingWait(seconds int) {
conf.WritingWait = time.Duration(seconds) * time.Second
}
// SetReadingWait sets the time for waiting that reading occur
func (conf *ClientConfig) SetReadingWait(seconds int) {
conf.ReadingWait = time.Duration(seconds) * time.Second
}
// SetLogger sets the default logger
func (conf *ClientConfig) SetLogger(logger *logger.Logger) {
conf.Logger = logger
}