Passed
Pull Request — master (#1232)
by Tolga
02:24
created

pkg/database/postgres/options.go   A

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 16
eloc 28
dl 0
loc 58
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A postgres.MaxOpenConnections 0 3 2
A postgres.MaxIdleConnections 0 3 2
A postgres.MaxConnectionLifeTime 0 3 2
A postgres.MaxConnectionIdleTime 0 3 2
A postgres.MaxRetries 0 3 2
A postgres.WatchBufferSize 0 3 2
A postgres.MaxDataPerWrite 0 3 2
A postgres.SimpleMode 0 3 2
1
package postgres
2
3
import (
4
	"time"
5
)
6
7
// Option - Option type
8
type Option func(*Postgres)
9
10
// MaxOpenConnections - Defines maximum open connections for postgresql db
11
func MaxOpenConnections(size int) Option {
12
	return func(c *Postgres) {
13
		c.maxOpenConnections = size
14
	}
15
}
16
17
// MaxIdleConnections - Defines maximum idle connections for postgresql db
18
func MaxIdleConnections(c int) Option {
19
	return func(p *Postgres) {
20
		p.maxIdleConnections = c
21
	}
22
}
23
24
// MaxConnectionIdleTime - Defines maximum connection idle for postgresql db
25
func MaxConnectionIdleTime(d time.Duration) Option {
26
	return func(p *Postgres) {
27
		p.maxConnectionIdleTime = d
28
	}
29
}
30
31
// MaxConnectionLifeTime - Defines maximum connection lifetime for postgresql db
32
func MaxConnectionLifeTime(d time.Duration) Option {
33
	return func(p *Postgres) {
34
		p.maxConnectionLifeTime = d
35
	}
36
}
37
38
func MaxDataPerWrite(v int) Option {
39
	return func(c *Postgres) {
40
		c.maxDataPerWrite = v
41
	}
42
}
43
44
func WatchBufferSize(v int) Option {
45
	return func(c *Postgres) {
46
		c.watchBufferSize = v
47
	}
48
}
49
50
func MaxRetries(v int) Option {
51
	return func(c *Postgres) {
52
		c.maxRetries = v
53
	}
54
}
55
56
func SimpleMode(v bool) Option {
57
	return func(c *Postgres) {
58
		c.simpleMode = v
59
	}
60
}
61