-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.go
43 lines (37 loc) · 1.21 KB
/
db.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
package config
import (
"fmt"
"os"
)
type DatabaseConfiguration struct {
Driver string
Dbname string
Username string
Password string
Host string
Port string
LogMode bool
}
func DbConfiguration() (string, string) {
masterDBName := os.Getenv("MASTER_DB_NAME")
masterDBUser := os.Getenv("MASTER_DB_USER")
masterDBPassword := os.Getenv("MASTER_DB_PASSWORD")
masterDBHost := os.Getenv("MASTER_DB_HOST")
masterDBPort := os.Getenv("MASTER_DB_PORT")
masterDBSslMode := os.Getenv("MASTER_SSL_MODE")
replicaDBName := os.Getenv("REPLICA_DB_NAME")
replicaDBUser := os.Getenv("REPLICA_DB_USER")
replicaDBPassword := os.Getenv("REPLICA_DB_PASSWORD")
replicaDBHost := os.Getenv("REPLICA_DB_HOST")
replicaDBPort := os.Getenv("REPLICA_DB_PORT")
replicaDBSslMode := os.Getenv("REPLICA_SSL_MODE")
masterDBDSN := fmt.Sprintf(
"host=%s user=%s password=%s dbname=%s port=%s sslmode=%s",
masterDBHost, masterDBUser, masterDBPassword, masterDBName, masterDBPort, masterDBSslMode,
)
replicaDBDSN := fmt.Sprintf(
"host=%s user=%s password=%s dbname=%s port=%s sslmode=%s",
replicaDBHost, replicaDBUser, replicaDBPassword, replicaDBName, replicaDBPort, replicaDBSslMode,
)
return masterDBDSN, replicaDBDSN
}