forked from open-horizon/anax
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostgresql.go
38 lines (30 loc) · 1.23 KB
/
postgresql.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
package config
import (
"fmt"
)
type PostgresqlConfig struct {
Host string
Port string
User string
Password string
DBName string
SSLMode string
MaxOpenConnections int
}
func (p PostgresqlConfig) MakeConnectionString() (string, string) {
// By default we will use SSL to communicate to the DB.
sslMode := "require"
if p.SSLMode != "" {
sslMode = p.SSLMode
}
connStr := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s", p.Host, p.Port, p.User, p.Password, p.DBName, sslMode)
traceString := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s", p.Host, p.Port, p.User, "********", p.DBName, sslMode)
if p.Password == "" {
connStr = fmt.Sprintf("host=%s port=%s user=%s dbname=%s sslmode=%s", p.Host, p.Port, p.User, p.DBName, sslMode)
traceString = fmt.Sprintf("host=%s port=%s user=%s dbname=%s sslmode=%s", p.Host, p.Port, p.User, p.DBName, sslMode)
}
return connStr, traceString
}
func (p PostgresqlConfig) String() string {
return fmt.Sprintf("Host: %v, Port: %v, User: %v, Password: %v, DBName: %v, SSLMode: %v MaxOpenConnections: %v", p.Host, p.Port, p.User, "******", p.DBName, p.SSLMode, p.MaxOpenConnections)
}