-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.go
93 lines (82 loc) · 2.67 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package avroipc
import (
"crypto/tls"
"time"
)
// Config provides a configuration for the client. Use the NewConfig method
// to create an instance of the Config and set all necessary parameters of
// the configuration.
type Config struct {
// Connection timeout for the built-in socket transport that limit time of
// connection to a Flume server.
//
// It is sane to always set this timeout before creating a new client
// instance because it will protect against hanging clients.
//
// Defaults to zero which means disabled connection timeout.
Timeout time.Duration
// Used to set read and write deadline of the built-in transports
// (actually, affects only the socket transport). It sets both deadlines
// together at the same time and there is no way to set them separately.
// These deadlines are used to limit execution time of reading and writing
// operations.
//
// This timeout is supposed to be always set to any appropriate for
// a particular situation value except maybe test and example
// configurations.
//
// Defaults to zero which means disabled read/write timeouts.
SendTimeout time.Duration
// A buffer size of the built-in buffered transport.
//
// Defaults to zero which means that the buffered transport won't be used.
BufferSize int
// A compression level of the built-in zlib transport.
//
// Defaults to zero which means that the compression will be disabled.
CompressionLevel int
// Use TLS Config
//
// Defaults to false
TLSConfig *tls.Config
}
// NewConfig returns a pointer to a new Config instance that is used to
// configure the client at a creation time. Invoking methods of the config
// instance may be chained with each other to specify all necessary config
// options in a single command. A NewConfig call may be also chained with
// other methods to inline config creations.
//
// config := NewConfig()
// config.WithTimeout(3*time.Second)
// client, err := NewClientWithConfig(config)
//
// or just
//
// client, err := NewClientWithConfig(NewConfig().WithTimeout(3*time.Second))
func NewConfig() *Config {
return &Config{}
}
// Sets the connection timeout.
func (c *Config) WithTimeout(t time.Duration) *Config {
c.Timeout = t
return c
}
// Sets the read/write timeouts together.
func (c *Config) WithSendTimeout(t time.Duration) *Config {
c.SendTimeout = t
return c
}
// Sets size of the internal buffer of the buffered transport.
func (c *Config) WithBufferSize(s int) *Config {
c.BufferSize = s
return c
}
// Sets the compression level of the zlib transport.
func (c *Config) WithCompressionLevel(l int) *Config {
c.CompressionLevel = l
return c
}
func (c *Config) WithTLSConfig(cfg *tls.Config) *Config {
c.TLSConfig = cfg
return c
}