Skip to content

Commit

Permalink
add support for sockets (mostly clarification)
Browse files Browse the repository at this point in the history
  • Loading branch information
luclu7 committed Dec 25, 2020
1 parent f95ab46 commit 44f07ca
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions extra/config.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions utils/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion utils/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 44f07ca

Please sign in to comment.