generated from akmamun/gin-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 3
/
db.go
43 lines (37 loc) · 1.3 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"
"github.com/spf13/viper"
)
type DatabaseConfiguration struct {
Driver string
Dbname string
Username string
Password string
Host string
Port string
LogMode bool
}
func DbConfiguration() (string, string) {
masterDBName := viper.GetString("MASTER_DB_NAME")
masterDBUser := viper.GetString("MASTER_DB_USER")
masterDBPassword := viper.GetString("MASTER_DB_PASSWORD")
masterDBHost := viper.GetString("MASTER_DB_HOST")
masterDBPort := viper.GetString("MASTER_DB_PORT")
masterDBSslMode := viper.GetString("MASTER_SSL_MODE")
replicaDBName := viper.GetString("REPLICA_DB_NAME")
replicaDBUser := viper.GetString("REPLICA_DB_USER")
replicaDBPassword := viper.GetString("REPLICA_DB_PASSWORD")
replicaDBHost := viper.GetString("REPLICA_DB_HOST")
replicaDBPort := viper.GetString("REPLICA_DB_PORT")
replicaDBSslMode := viper.GetString("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
}