Compare commits

...

7 Commits

Author SHA1 Message Date
Maël a1cd3ea5a1
Merge pull request #6 from outout14/deepsource-transform-f033f2c5
Format code with gofmt
2020-12-26 12:09:57 -04:00
Maël 6f8f0ce7d6
Merge pull request #8 from luclu7/add-socket-support
Add socket support
2020-12-26 12:08:53 -04:00
Luclu7 15910ae7a2
updated README.md 2020-12-25 03:16:09 +01:00
Luclu7 44f07ca2a2
add support for sockets (mostly clarification) 2020-12-25 03:06:20 +01:00
Luclu7 f95ab468b3
add built binary to gitignore 2020-12-25 02:33:41 +01:00
Luclu7 8220eacb10
config: fixed app_mode
also changed like Ip to IP and Db to DB
2020-12-25 02:31:28 +01:00
deepsource-autofix[bot] 2359e07146
Format code with gofmt
This commit fixes the style issues introduced in e9e84ea according to the output
from gofmt.

Details: https://deepsource.io/gh/outout14/sacrebleu-dns/transform/67d36107-8c80-4374-8608-5a30493582d4/
2020-12-24 01:45:10 +00:00
6 changed files with 29 additions and 24 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

@ -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.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