add support for sockets (mostly clarification)

This commit is contained in:
Luclu7 2020-12-25 03:06:20 +01:00
parent f95ab468b3
commit 44f07ca2a2
No known key found for this signature in database
GPG key ID: F157AA98AFB4C41B
3 changed files with 8 additions and 6 deletions

View file

@ -7,12 +7,14 @@ Logfile = true
Logdir = "/var/log/"
[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"
Password = "superSecretPassword"
Port = "3306"
DB = "sacrebleudatabase"
Type = "mysql" #postgresql or mysql
[Redis]
IP = "127.0.0.1"

View file

@ -32,13 +32,13 @@ func SQLDatabase(conf *Conf) {
}
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{
Logger: logger.Default.LogMode(gormLogLevel),
})
} 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{
Logger: logger.Default.LogMode(gormLogLevel),

View file

@ -10,7 +10,7 @@ type App struct {
//Database : Struct for SQL Database configuration in the config.ini file
type Database struct {
IP string `ini:"IP"`
Host string `ini:"Host"`
Port string
Username string
Password string