Merge pull request #8 from luclu7/add-socket-support

Add socket support
This commit is contained in:
Maël 2020-12-26 12:08:53 -04:00 committed by GitHub
commit 6f8f0ce7d6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 22 deletions

3
.gitignore vendored
View file

@ -12,3 +12,6 @@ Icon
config.ini
log/*
dist/*
# binary
sacrebleu-dns

View file

@ -38,24 +38,24 @@ You can show theses informations using ``./sacrebleu-dns -h``.
Variables names are case sensitives.
|Variable name|Type|Example|Informations|
|--|--|--|--|
| AppMode | string|``"production"``|Anything different than ``production`` will show debug messages
| app_mode | string|``"production"``|Anything different than ``production`` will show debug messages
| App | Section |
|IP|string|``":"``|IP address on which the DNS server must listen. Blank to listen on all IPs
|Port|int|``5353``|Port on which the DNS server must listen
|Logfile|bool|``true``|Enable or disable file logs.
|Database|Section|
|IP|string|``"127.0.0.1"``|SQL Database IP
|Type|string|``"postgresql"``|SQL Database type. ``"postgresql"`` or ``"mysql"`` (anything different than ``"postgresql"`` will rollback to ``"mysql"``)
|Host|string|``"127.0.0.1"`` ``"/var/run/postgres"``|Can be either an IP or a path to a socket for Postgres
|Username|string|``"sacrebleu"``|SQL Database Username
|Password|string|``"superSecretPassword"``|SQL Database Password
|Password|string|``"superSecretPassword"``|SQL Database Password (optional)
|Port|string|``"5432"``|SQL Database port (``"5432"`` for postgres or ``"3306"`` for MySQL by default)
|Db|string|``"sacrebleudatabase"``|SQL Database Name
|Type|string|``"postgresql"``|SQL Database type. ``"postgresql"`` or ``"mysql"`` (anything different than ``"postgresql"`` will rollback to ``"mysql"``
|Redis|Section
|IP|string|``"127.0.0.1"``|Redis Database IP
|Password|string|``""``|Redis Database Password
|Port|int|``6379``|Redis Database port
|Db|int|``0``|Redis Database ID
|Ttl|int|``10``|Redis Time To Live (in seconds)
|DB|int|``0``|Redis Database ID
|TTL|int|``10``|Redis Time To Live (in seconds)
## What is working
- Read records (stricts & wildcard) from MySQL

View file

@ -1,4 +1,4 @@
AppMode = "production" #Anything != production will show DEBUG messages
app_mode = "production" #Anything != production will show DEBUG messages
[App]
IP = ""
@ -7,16 +7,18 @@ 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
DB = "sacrebleudatabase"
[Redis]
IP = "127.0.0.1"
Port = 6379
Password = ""
Db = 0
Ttl = 10 #In seconds
DB = 0
TTL = 10 #In seconds

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

@ -3,33 +3,33 @@ package utils
//App : Struct for App (dns server) configuration in the config.ini file
type App struct {
Port int
IP string
IP string `ini:"IP"`
Logdir string
Logfile bool
}
//Database : Struct for SQL Database configuration in the config.ini file
type Database struct {
IP string
Host string `ini:"Host"`
Port string
Username string
Password string
Db string
Db string `ini:"DB"`
Type string
}
//Redis : Struct for Redis Database configuration in the config.ini file
type Redis struct {
IP string
IP string `ini:"IP"`
Port int
Password string
Db int
TTL int
Db int `ini:"DB"`
TTL int `ini:"TTL"`
}
//Conf : Struct for the whole config.ini file when it will be parsed by go-ini
type Conf struct {
AppMode string
AppMode string `ini:"app_mode"`
App
Database
Redis