-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
73 lines (59 loc) · 1.64 KB
/
config.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
package stomp
import (
"crypto/tls"
"fmt"
"net"
"time"
)
const (
// Version is the supported STOMP version.
Version string = "1.2"
)
// Heartbeat is the STOMP Heartbeat configuration.
type Heartbeat struct {
Send time.Duration
Recv time.Duration
}
func (h Heartbeat) toString() string {
return fmt.Sprintf("%d,%d", int(h.Send.Seconds()*1000), int(h.Recv.Seconds()*1000))
}
func maxDuration(a time.Duration, b time.Duration) time.Duration {
if a > b {
return a
}
return b
}
// Config is the STOMP client configuration.
type Config struct {
// The name of the virtual host.
Host string
// The user identifier.
Login string
// The password used to authenticate the client.
Passcode string
// The heart-beat configuration for the client and server connection.
Heartbeat Heartbeat
}
// DefaultConfig is a default client configuration.
// It only defines a Host parameter.
var DefaultConfig = &Config{
Host: "/",
}
// TransportConfig defines the connection level transport config.
type TransportConfig struct {
// Dial defines the dial function used for creating connections.
// If Dial is nil, net.Dial is used.
Dial func(network, addr string) (net.Conn, error)
// TLSConfig defines the TLS configuration to use.
// If TLSConfig is nil, then the connection will not used TLS.
TLSConfig *tls.Config
// TLSHandshakeTimeout defines the maximum time to
// wait for TLS handshake before timing out.
// Zero means no timeout.
// If TLSConfig is nil, the timeout will be ignored.
TLSHandshakeTimeout time.Duration
}
// DefaultTransportConfig defines the default transport config.
var DefaultTransportConfig = &TransportConfig{
Dial: net.Dial,
}