-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
54 lines (50 loc) · 1.5 KB
/
config.go
File metadata and controls
54 lines (50 loc) · 1.5 KB
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
package tcppool
import (
"time"
"github.com/meliadamian17/tcppool/internal"
"github.com/meliadamian17/tcppool/internal/backoff"
"github.com/meliadamian17/tcppool/utils"
)
// Config represents the configuration for a connection pool.
// It encapsulates various settings like connection limits, timeouts, retries,
// backoff strategies, and event hooks.
type Config struct {
impl *internal.ConfigImpl
}
// NewConfig creates a new Config object with the specified parameters.
//
// Parameters:
// - address: The network address for the pool's connections.
// - name: A custom name for the pool (if empty, it's generated based on the address).
// - maxConnections: The maximum number of active connections in the pool.
// - connTimeout: The timeout for establishing new connections.
// - idleTimeout: The timeout for cleaning up idle connections.
// - maxRetries: The maximum number of retries for failed connections.
// - backoff: The backoff strategy for retrying failed connections.
// - hooks: A set of custom hooks for pool events.
//
// Returns:
// - A pointer to the created Config object.
func NewConfig(
address, name string,
maxConnections int,
connTimeout, idleTimeout time.Duration,
maxRetries uint,
backoff backoff.Backoff,
hooks PoolHooks,
) *Config {
if len(name) == 0 {
name = utils.IDByAddress(address)
}
impl := internal.NewConfig(
address,
name,
maxConnections,
connTimeout,
idleTimeout,
maxRetries,
backoff,
hooks.ToInternal(),
)
return &Config{impl: impl}
}