-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathoptions.go
47 lines (41 loc) · 1.6 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
package mariadb
import (
"fmt"
"math"
"github.com/kubemq-io/kubemq-targets/config"
)
const (
defaultMaxIdleConnections = 10
defaultMaxOpenConnections = 100
defaultConnectionMaxLifetimeSeconds = 3600
)
type options struct {
connection string
// maxIdleConnections sets the maximum number of connections in the idle connection pool
maxIdleConnections int
// maxOpenConnections sets the maximum number of open connections to the database.
maxOpenConnections int
// connectionMaxLifetimeSeconds sets the maximum amount of time a connection may be reused.
connectionMaxLifetimeSeconds int
}
func parseOptions(cfg config.Spec) (options, error) {
o := options{}
var err error
o.connection, err = cfg.Properties.MustParseString("connection")
if err != nil {
return options{}, fmt.Errorf("error parsing connection string, %w", err)
}
o.maxIdleConnections, err = cfg.Properties.ParseIntWithRange("max_idle_connections", defaultMaxIdleConnections, 1, math.MaxInt32)
if err != nil {
return options{}, fmt.Errorf("error parsing max_idle_connections value, %w", err)
}
o.maxOpenConnections, err = cfg.Properties.ParseIntWithRange("max_open_connections", defaultMaxOpenConnections, 1, math.MaxInt32)
if err != nil {
return options{}, fmt.Errorf("error parsing max_open_connections value, %w", err)
}
o.connectionMaxLifetimeSeconds, err = cfg.Properties.ParseIntWithRange("connection_max_lifetime_seconds", defaultConnectionMaxLifetimeSeconds, 1, math.MaxInt32)
if err != nil {
return options{}, fmt.Errorf("error parsing connection_max_lifetime_seconds value, %w", err)
}
return o, nil
}