all: fix fmt

This commit is contained in:
Stanislav Chzhen 2023-03-01 12:25:14 +03:00
parent d54022baa6
commit 2f3e25bee5
3 changed files with 16 additions and 19 deletions

View File

@ -42,7 +42,7 @@ type getConfigResp struct {
// Ignored is the list of host names, which should not be written to log. // Ignored is the list of host names, which should not be written to log.
Ignored []string `json:"ignored"` Ignored []string `json:"ignored"`
// Interval is the querylog rotation interval in milliseconds // Interval is the querylog rotation interval in milliseconds.
Interval float64 `json:"interval"` Interval float64 `json:"interval"`
// Enabled shows if the querylog is enabled. It is an aghalg.NullBool to // Enabled shows if the querylog is enabled. It is an aghalg.NullBool to
@ -103,8 +103,7 @@ func (l *queryLog) handleQueryLogInfo(w http.ResponseWriter, r *http.Request) {
ivl := l.conf.RotationIvl ivl := l.conf.RotationIvl
ok := checkInterval(ivl) if !checkInterval(ivl) {
if !ok {
// NOTE: If interval is custom we set it to 90 days for compatibility // NOTE: If interval is custom we set it to 90 days for compatibility
// with old API. // with old API.
ivl = timeutil.Day * 90 ivl = timeutil.Day * 90

View File

@ -11,6 +11,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp" "github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/AdGuardHome/internal/aghnet" "github.com/AdguardTeam/AdGuardHome/internal/aghnet"
"github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/timeutil"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
) )
@ -116,10 +117,7 @@ func (s *StatsCtx) handleGetStatsConfig(w http.ResponseWriter, r *http.Request)
Interval: float64(s.limit.Milliseconds()), Interval: float64(s.limit.Milliseconds()),
Ignored: ignored, Ignored: ignored,
} }
err := aghhttp.WriteJSONResponse(w, r, resp) _ = aghhttp.WriteJSONResponse(w, r, resp)
if err != nil {
log.Debug("stats: write response: %s", err)
}
} }
// handleStatsConfig handles requests to the POST /control/stats_config // handleStatsConfig handles requests to the POST /control/stats_config
@ -146,11 +144,12 @@ func (s *StatsCtx) handleStatsConfig(w http.ResponseWriter, r *http.Request) {
s.lock.Lock() s.lock.Lock()
defer s.lock.Unlock() defer s.lock.Unlock()
s.setLimitLocked(int(reqData.IntervalDays)) limit := time.Duration(reqData.IntervalDays) * timeutil.Day
s.setLimitLocked(limit)
} }
// handlePutStatsConfig handles requests to the PUT // handlePutStatsConfig handles requests to the PUT /control/stats/config/update
// /control/stats/config/update endpoint. // endpoint.
func (s *StatsCtx) handlePutStatsConfig(w http.ResponseWriter, r *http.Request) { func (s *StatsCtx) handlePutStatsConfig(w http.ResponseWriter, r *http.Request) {
reqData := getConfigResp{} reqData := getConfigResp{}
err := json.NewDecoder(r.Body).Decode(&reqData) err := json.NewDecoder(r.Body).Decode(&reqData)
@ -171,15 +170,15 @@ func (s *StatsCtx) handlePutStatsConfig(w http.ResponseWriter, r *http.Request)
defer s.configModified() defer s.configModified()
s.lock.Lock()
defer s.lock.Unlock()
if reqData.Enabled == aghalg.NBNull { if reqData.Enabled == aghalg.NBNull {
aghhttp.Error(r, w, http.StatusUnprocessableEntity, "enabled is null") aghhttp.Error(r, w, http.StatusUnprocessableEntity, "enabled is null")
return return
} }
s.lock.Lock()
defer s.lock.Unlock()
s.enabled = reqData.Enabled == aghalg.NBTrue s.enabled = reqData.Enabled == aghalg.NBTrue
s.limit = ivl s.limit = ivl

View File

@ -453,15 +453,14 @@ func (s *StatsCtx) periodicFlush() {
log.Debug("periodic flushing finished") log.Debug("periodic flushing finished")
} }
// setLimitLocked sets the limit interval without locking. For internal use // setLimitLocked sets the limit without locking. For internal use only.
// only.
// //
// TODO(s.chzhen): Remove it when migration to the new API is over. // TODO(s.chzhen): Remove it when migration to the new API is over.
func (s *StatsCtx) setLimitLocked(limitDays int) { func (s *StatsCtx) setLimitLocked(limit time.Duration) {
if limitDays != 0 { if limit != 0 {
s.enabled = true s.enabled = true
s.limit = time.Duration(limitDays) * timeutil.Day s.limit = limit
log.Debug("stats: set limit: %d days", limitDays) log.Debug("stats: set limit: %d days", int(limit.Hours()/24))
return return
} }