Pull request: all: fix lint and naming issues

Merge in DNS/adguard-home from 2276-fix-lint to master

Updates #2276.

Squashed commit of the following:

commit 433f44cc7b674a20ed60a9d29466ba888b3ef66e
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon Dec 7 14:14:28 2020 +0300

    querylog: improve code and documentation

commit 851df97d2a87de5e7180a502055ee6f1a6defdca
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Dec 4 20:36:32 2020 +0300

    all: fix lint and naming issues
This commit is contained in:
Ainar Garipov
2020-12-07 14:32:06 +03:00
parent 63e513e33e
commit a572876775
14 changed files with 61 additions and 47 deletions

View File

@@ -12,7 +12,9 @@ import (
"github.com/miekg/dns"
)
var logEntryHandlers = map[string](func(t json.Token, ent *logEntry) error){
type logEntryHandler (func(t json.Token, ent *logEntry) error)
var logEntryHandlers = map[string]logEntryHandler{
"IP": func(t json.Token, ent *logEntry) error {
v, ok := t.(string)
if !ok {
@@ -203,16 +205,24 @@ func decodeLogEntry(ent *logEntry, str string) {
if _, ok := keyToken.(json.Delim); ok {
continue
}
key := keyToken.(string)
key, ok := keyToken.(string)
if !ok {
log.Debug("decodeLogEntry: keyToken is %T and not string", keyToken)
return
}
handler, ok := logEntryHandlers[key]
if !ok {
continue
}
val, err := dec.Token()
if err != nil {
return
}
if err := handler(val, ent); err != nil {
if err = handler(val, ent); err != nil {
log.Debug("decodeLogEntry err: %s", err)
return
}