This repository has been archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
options.go
69 lines (54 loc) · 1.79 KB
/
options.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
package client
import (
"io"
"os"
"time"
)
// OptionToggle represents the value of a togglable option
type OptionToggle int
const (
// OptUnset defines unset togglable options
OptUnset OptionToggle = iota
// OptDisabled defines disabled togglable options
OptDisabled
// OptEnabled defines enabled togglable options
OptEnabled
)
// Options represents the options used during the creation a new client instance
type Options struct {
// Hooks define the callback hook functions provided by the user to define behavior
// on certain events
Hooks Hooks
// DefaultRequestTimeout defines the default request timeout duration used in client.Request
DefaultRequestTimeout time.Duration
// ReconnectionInterval defines the interval at which autoconnect should poll for a connection.
// If undefined then the default value of 2 seconds is applied
ReconnectionInterval time.Duration
// If autoconnect is enabled, client.Request, client.TimedRequest and client.RestoreSession
// won't immediately return a disconnected error if there's no active connection to the server,
// instead they will automatically try to reestablish the connection
// before the timeout is triggered and a timeout error is returned.
// Autoconnect is enabled by default
Autoconnect OptionToggle
WarnLog io.Writer
ErrorLog io.Writer
}
// SetDefaults sets default values for undefined required options
func (opts *Options) SetDefaults() {
opts.Hooks.SetDefaults()
if opts.Autoconnect == OptUnset {
opts.Autoconnect = OptEnabled
}
if opts.DefaultRequestTimeout < 1 {
opts.DefaultRequestTimeout = 60 * time.Second
}
if opts.ReconnectionInterval < 1 {
opts.ReconnectionInterval = 2 * time.Second
}
if opts.WarnLog == nil {
opts.WarnLog = os.Stdout
}
if opts.ErrorLog == nil {
opts.ErrorLog = os.Stderr
}
}