From 3737e17ecf210fcb8c4c97e0f86fb6582a1e432b Mon Sep 17 00:00:00 2001 From: Mael GRAMAIN Date: Tue, 22 Dec 2020 20:20:06 -0400 Subject: [PATCH] Switched sql funcs returns from int to bool --- utils/queries.go | 6 +++--- utils/sql.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/utils/queries.go b/utils/queries.go index b3ad36b..66f046f 100644 --- a/utils/queries.go +++ b/utils/queries.go @@ -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) diff --git a/utils/sql.go b/utils/sql.go index a5cefeb..2f53731 100644 --- a/utils/sql.go +++ b/utils/sql.go @@ -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 }