forked from shoekstra/go-dbmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection.go
60 lines (52 loc) · 1.33 KB
/
connection.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
package dbmanager
// Connector represents a database connection
type Connector interface {
Connect() error
Disconnect() error
}
// Connection represents the configuration for establishing a connection
type Connection struct {
Host string
Database string
Port string
Username string
Password string
SSLMode string
SSL bool
}
// WithHost sets the host in the connection configuration
func WithHost(host string) func(*Connection) {
return func(c *Connection) {
c.Host = host
}
}
// WithDatabase sets the database in the connection configuration
func WithDatabase(database string) func(*Connection) {
return func(c *Connection) {
c.Database = database
}
}
// WithPort sets the port in the connection configuration
func WithPort(port string) func(*Connection) {
return func(c *Connection) {
c.Port = port
}
}
// WithUsername sets the username in the connection configuration
func WithUsername(username string) func(*Connection) {
return func(c *Connection) {
c.Username = username
}
}
// WithPassword sets the password in the connection configuration
func WithPassword(password string) func(*Connection) {
return func(c *Connection) {
c.Password = password
}
}
// WithSSL sets the SSL flag in the connection configuration
func WithSSL(ssl bool) func(*Connection) {
return func(c *Connection) {
c.SSL = ssl
}
}