Compare commits

..

No commits in common. "a1cd3ea5a1462c21542b9f45414c5190e55dcc3f" and "e9e84ea07621a83dd2051a440f02a4891d6e4ce4" have entirely different histories.

6 changed files with 24 additions and 29 deletions

3
.gitignore vendored
View file

@ -12,6 +12,3 @@ 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|
|--|--|--|--|
| app_mode | string|``"production"``|Anything different than ``production`` will show debug messages
| AppMode | 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|
|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
|IP|string|``"127.0.0.1"``|SQL Database IP
|Username|string|``"sacrebleu"``|SQL Database Username
|Password|string|``"superSecretPassword"``|SQL Database Password (optional)
|Password|string|``"superSecretPassword"``|SQL Database Password
|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 @@
app_mode = "production" #Anything != production will show DEBUG messages
AppMode = "production" #Anything != production will show DEBUG messages
[App]
IP = ""
@ -7,18 +7,16 @@ Logfile = true
Logdir = "/var/log/"
[Database]
# 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/
IP = "127.0.0.1"
Username = "sacrebleu"
Password = "superSecretPassword"
Port = "3306"
DB = "sacrebleudatabase"
Db = "sacrebleudatabase"
Type = "mysql" #postgresql or mysql
[Redis]
IP = "127.0.0.1"
Port = 6379
Password = ""
DB = 0
TTL = 10 #In seconds
Db = 0
Ttl = 10 #In seconds

View file

@ -21,8 +21,8 @@ var DB *sql.DB
//Main loop
func main() {
configPatch := flag.String("config", "config.ini", "the patch to the config file") //Get the config patch from --config flag
sqlMigration := flag.Bool("sqlmigrate", false, "initialize / migrate the database") //Detect if migration asked
configPatch := flag.String("config", "config.ini", "the patch to the config file") //Get the config patch from --config flag
sqlMigration := flag.Bool("sqlmigrate", false, "initialize / migrate the database") //Detect if migration asked
flag.Parse()
//Load the INI configuration file

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.Host, 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.IP, 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.Host, 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.IP, 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 `ini:"IP"`
IP string
Logdir string
Logfile bool
}
//Database : Struct for SQL Database configuration in the config.ini file
type Database struct {
Host string `ini:"Host"`
IP string
Port string
Username string
Password string
Db string `ini:"DB"`
Db string
Type string
}
//Redis : Struct for Redis Database configuration in the config.ini file
type Redis struct {
IP string `ini:"IP"`
IP string
Port int
Password string
Db int `ini:"DB"`
TTL int `ini:"TTL"`
Db int
TTL int
}
//Conf : Struct for the whole config.ini file when it will be parsed by go-ini
type Conf struct {
AppMode string `ini:"app_mode"`
AppMode string
App
Database
Redis