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 config.ini
log/* log/*
dist/* dist/*
# binary
sacrebleu-dns

View file

@ -38,24 +38,24 @@ You can show theses informations using ``./sacrebleu-dns -h``.
Variables names are case sensitives. Variables names are case sensitives.
|Variable name|Type|Example|Informations| |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 | | App | Section |
|IP|string|``":"``|IP address on which the DNS server must listen. Blank to listen on all IPs |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 |Port|int|``5353``|Port on which the DNS server must listen
|Logfile|bool|``true``|Enable or disable file logs. |Logfile|bool|``true``|Enable or disable file logs.
|Database|Section| |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 |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) |Port|string|``"5432"``|SQL Database port (``"5432"`` for postgres or ``"3306"`` for MySQL by default)
|Db|string|``"sacrebleudatabase"``|SQL Database Name |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 |Redis|Section
|IP|string|``"127.0.0.1"``|Redis Database IP |IP|string|``"127.0.0.1"``|Redis Database IP
|Password|string|``""``|Redis Database Password |Password|string|``""``|Redis Database Password
|Port|int|``6379``|Redis Database port |Port|int|``6379``|Redis Database port
|Db|int|``0``|Redis Database ID |DB|int|``0``|Redis Database ID
|Ttl|int|``10``|Redis Time To Live (in seconds) |TTL|int|``10``|Redis Time To Live (in seconds)
## What is working ## What is working
- Read records (stricts & wildcard) from MySQL - 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] [App]
IP = "" IP = ""
@ -7,16 +7,18 @@ Logfile = true
Logdir = "/var/log/" Logdir = "/var/log/"
[Database] [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" Username = "sacrebleu"
Password = "superSecretPassword" Password = "superSecretPassword"
Port = "3306" Port = "3306"
Db = "sacrebleudatabase" DB = "sacrebleudatabase"
Type = "mysql" #postgresql or mysql
[Redis] [Redis]
IP = "127.0.0.1" IP = "127.0.0.1"
Port = 6379 Port = 6379
Password = "" Password = ""
Db = 0 DB = 0
Ttl = 10 #In seconds TTL = 10 #In seconds

View file

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

View file

@ -32,13 +32,13 @@ func SQLDatabase(conf *Conf) {
} }
if conf.Database.Type == "postgresql" { 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{ db, err = gorm.Open(postgres.Open(dsn), &gorm.Config{
Logger: logger.Default.LogMode(gormLogLevel), Logger: logger.Default.LogMode(gormLogLevel),
}) })
} else { } 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{ db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
Logger: logger.Default.LogMode(gormLogLevel), 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 //App : Struct for App (dns server) configuration in the config.ini file
type App struct { type App struct {
Port int Port int
IP string IP string `ini:"IP"`
Logdir string Logdir string
Logfile bool Logfile bool
} }
//Database : Struct for SQL Database configuration in the config.ini file //Database : Struct for SQL Database configuration in the config.ini file
type Database struct { type Database struct {
IP string Host string `ini:"Host"`
Port string Port string
Username string Username string
Password string Password string
Db string Db string `ini:"DB"`
Type string Type string
} }
//Redis : Struct for Redis Database configuration in the config.ini file //Redis : Struct for Redis Database configuration in the config.ini file
type Redis struct { type Redis struct {
IP string IP string `ini:"IP"`
Port int Port int
Password string Password string
Db int Db int `ini:"DB"`
TTL int TTL int `ini:"TTL"`
} }
//Conf : Struct for the whole config.ini file when it will be parsed by go-ini //Conf : Struct for the whole config.ini file when it will be parsed by go-ini
type Conf struct { type Conf struct {
AppMode string AppMode string `ini:"app_mode"`
App App
Database Database
Redis Redis