diff --git a/extra/config.ini.example b/extra/config.ini.example index 47c7be1..7b75ebf 100644 --- a/extra/config.ini.example +++ b/extra/config.ini.example @@ -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" diff --git a/utils/sql.go b/utils/sql.go index b1f512d..f87f302 100644 --- a/utils/sql.go +++ b/utils/sql.go @@ -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), diff --git a/utils/structs.go b/utils/structs.go index d7b0a54..c7fa7a5 100644 --- a/utils/structs.go +++ b/utils/structs.go @@ -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