Switched sql funcs returns from int to bool

This commit is contained in:
Mael G. 2020-12-22 20:20:06 -04:00
parent 02ee609cc4
commit 3737e17ecf
2 changed files with 6 additions and 6 deletions

View File

@ -15,7 +15,7 @@ func GetRecord(entry Record) Record {
redisKey := entry.Fqdn + "--" + fmt.Sprint(entry.Qtype)
result, redisErr := redisCheckForRecord(redisKey, entry)
var sqlErr int //The err returned for sqlCheckForRecord or sqlCheckForReverse6Wildcard
var sqlErr bool //The err returned for sqlCheckForRecord or sqlCheckForReverse6Wildcard
//If reverse DNS
reverseCheck := IsReverse(entry.Fqdn)
@ -26,7 +26,7 @@ func GetRecord(entry Record) Record {
//Check for it in the SQL database
logrus.Debug("QUERIES : Check for strict reverse in MySQL")
result, sqlErr = sqlCheckForRecord(redisKey, entry.Fqdn, entry)
if sqlErr == 1 {
if sqlErr {
//Check for wildcard reverse in the SQL
logrus.Debug("QUERIES : Check for wildcard reverse in MySQL")
result, _ = sqlCheckForReverse6Wildcard(redisKey, entry.Fqdn, entry)
@ -57,7 +57,7 @@ func GetRecord(entry Record) Record {
//Check for strict record in mysql
logrus.Debug("QUERIES : Check for strict record in MSQL")
result, sqlErr = sqlCheckForRecord(redisKey, entry.Fqdn, entry)
if sqlErr == 1 {
if sqlErr {
//Check for wildcard record in mysql
logrus.Debug("QUERIES : Check for wildcard in MSQL")
result, _ = sqlCheckForRecord(redismdKey, fmt.Sprint(mainDomainKey), entry)

View File

@ -35,7 +35,7 @@ func SQLDatabase(conf *Conf) {
}
//Check for a record in the SQL database
func sqlCheckForRecord(redisKey string, dKey string, entry Record) (Record, int) {
func sqlCheckForRecord(redisKey string, dKey string, entry Record) (Record, bool) {
db.Where("name = ? AND type = ?", dKey, entry.Qtype).First(&entry)
logrus.Debugf("SQL : %s => %s", entry.Fqdn, entry.Content) //log the result
@ -44,10 +44,10 @@ func sqlCheckForRecord(redisKey string, dKey string, entry Record) (Record, int)
//Cache the request in Redis if any result
logrus.Debugf("REDIS : Set entry for %s", redisKey)
_ = redisSet(redisDb, redisKey, 30*time.Second, entry) //Set it in the Redis database for 30sec
return entry, 0
return entry, false
}
//Else return 1 for err
return entry, 1
return entry, true
}