Pull request:* all: fix all staticcheck simplification and unused warnings

Merge in DNS/adguard-home from 2270-fix-s-u-warnings to master

Squashed commit of the following:

commit 03e0f78bd471057007c2d4042ee26eda2bbc9b29
Merge: 50dc3ef5c 7e16fda57
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Fri Nov 6 11:54:09 2020 +0300

    Merge branch 'master' into 2270-fix-s-u-warnings

commit 50dc3ef5c44a5fdc941794c26784b0c44d7b5aa0
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Thu Nov 5 19:48:54 2020 +0300

    * all: improve code quality

commit d6d804f759ce3e47154a389b427550e72c4b9090
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Thu Nov 5 18:03:35 2020 +0300

    * all: fix all staticcheck simplification and unused warnings

    Closes #2270.
This commit is contained in:
Eugene Burkov
2020-11-06 12:15:08 +03:00
parent 7e16fda57b
commit 3e1f922252
24 changed files with 159 additions and 210 deletions

View File

@@ -131,7 +131,7 @@ func checkInterval(days uint32) bool {
func (s *statsCtx) dbOpen() bool {
var err error
log.Tracef("db.Open...")
s.db, err = bolt.Open(s.conf.Filename, 0644, nil)
s.db, err = bolt.Open(s.conf.Filename, 0o644, nil)
if err != nil {
log.Error("Stats: open DB: %s: %s", s.conf.Filename, err)
if err.Error() == "invalid argument" {
@@ -274,10 +274,7 @@ func convertMapToArray(m map[string]uint64, max int) []countPair {
a = append(a, pair)
}
less := func(i, j int) bool {
if a[i].Count >= a[j].Count {
return true
}
return false
return a[j].Count < a[i].Count
}
sort.Slice(a, less)
if max > len(a) {
@@ -297,15 +294,17 @@ func convertArrayToMap(a []countPair) map[string]uint64 {
func serialize(u *unit) *unitDB {
udb := unitDB{}
udb.NTotal = u.nTotal
for _, it := range u.nResult {
udb.NResult = append(udb.NResult, it)
}
udb.NResult = append(udb.NResult, u.nResult...)
if u.nTotal != 0 {
udb.TimeAvg = uint32(u.timeSum / u.nTotal)
}
udb.Domains = convertMapToArray(u.domains, maxDomains)
udb.BlockedDomains = convertMapToArray(u.blockedDomains, maxDomains)
udb.Clients = convertMapToArray(u.clients, maxClients)
return &udb
}
@@ -499,7 +498,8 @@ func (s *statsCtx) loadUnits(limit uint32) ([]*unitDB, uint32) {
curID := s.unit.id
s.unitLock.Unlock()
units := []*unitDB{} //per-hour units
// Per-hour units.
units := []*unitDB{}
firstID := curID - limit + 1
for i := firstID; i != curID; i++ {
u := s.loadUnitFromDB(tx, i)