add support for sockets (mostly clarification)
This commit is contained in:
parent
f95ab468b3
commit
44f07ca2a2
3 changed files with 8 additions and 6 deletions
|
@ -7,12 +7,14 @@ Logfile = true
|
||||||
Logdir = "/var/log/"
|
Logdir = "/var/log/"
|
||||||
|
|
||||||
[Database]
|
[Database]
|
||||||
IP = "127.0.0.1"
|
# Type can be either postgresql or mysql
|
||||||
|
Type = "postgresql"
|
||||||
|
# if type if postgres, you can also connect to the DB with a socket file
|
||||||
|
Host = "127.0.0.1" # can be either an IP address or a socket, it's often /var/run/postgresql/
|
||||||
Username = "sacrebleu"
|
Username = "sacrebleu"
|
||||||
Password = "superSecretPassword"
|
Password = "superSecretPassword"
|
||||||
Port = "3306"
|
Port = "3306"
|
||||||
DB = "sacrebleudatabase"
|
DB = "sacrebleudatabase"
|
||||||
Type = "mysql" #postgresql or mysql
|
|
||||||
|
|
||||||
[Redis]
|
[Redis]
|
||||||
IP = "127.0.0.1"
|
IP = "127.0.0.1"
|
||||||
|
|
|
@ -32,13 +32,13 @@ func SQLDatabase(conf *Conf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.Database.Type == "postgresql" {
|
if conf.Database.Type == "postgresql" {
|
||||||
dsn := fmt.Sprintf("user=%s password=%s host=%s port=%s database=%s sslmode=disable", conf.Database.Username, conf.Database.Password, conf.Database.IP, conf.Database.Port, conf.Database.Db)
|
dsn := fmt.Sprintf("user=%s password=%s host=%s port=%s database=%s sslmode=disable", conf.Database.Username, conf.Database.Password, conf.Database.Host, conf.Database.Port, conf.Database.Db)
|
||||||
|
|
||||||
db, err = gorm.Open(postgres.Open(dsn), &gorm.Config{
|
db, err = gorm.Open(postgres.Open(dsn), &gorm.Config{
|
||||||
Logger: logger.Default.LogMode(gormLogLevel),
|
Logger: logger.Default.LogMode(gormLogLevel),
|
||||||
})
|
})
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", conf.Database.Username, conf.Database.Password, conf.Database.IP, conf.Database.Port, conf.Database.Db)
|
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", conf.Database.Username, conf.Database.Password, conf.Database.Host, conf.Database.Port, conf.Database.Db)
|
||||||
|
|
||||||
db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
|
db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
|
||||||
Logger: logger.Default.LogMode(gormLogLevel),
|
Logger: logger.Default.LogMode(gormLogLevel),
|
||||||
|
|
|
@ -10,7 +10,7 @@ type App struct {
|
||||||
|
|
||||||
//Database : Struct for SQL Database configuration in the config.ini file
|
//Database : Struct for SQL Database configuration in the config.ini file
|
||||||
type Database struct {
|
type Database struct {
|
||||||
IP string `ini:"IP"`
|
Host string `ini:"Host"`
|
||||||
Port string
|
Port string
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
|
|
Loading…
Reference in a new issue