diff --git a/Makefile b/Makefile index 45ff2d80..e61d09b1 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ GO_BUILD_LD_FLAGS:=\ GO_BUILD_OUTPUT:=$(BIN_OUT_DIR)/$(BINARY_NAME)$(BINARY_SUFFIX) # define version of golangci-lint here. If defined in tools.go, go mod perfoms automatically downgrade to older version which doesn't work with golang >=1.18 -GOLANG_LINT_VERSION=v1.54.2 +GOLANG_LINT_VERSION=v1.57.2 GINKGO_PROCS?=-p diff --git a/cache/stringcache/string_caches.go b/cache/stringcache/string_caches.go index 9da579c4..45c7120f 100644 --- a/cache/stringcache/string_caches.go +++ b/cache/stringcache/string_caches.go @@ -222,6 +222,7 @@ func (r *wildcardCacheFactory) addEntry(entry string) bool { entry = normalizeWildcard(entry) r.trie.Insert(entry) + r.cnt++ return true diff --git a/cmd/blocking.go b/cmd/blocking.go index f4dc5e51..e77120e3 100644 --- a/cmd/blocking.go +++ b/cmd/blocking.go @@ -109,6 +109,7 @@ func statusBlocking(_ *cobra.Command, _ []string) error { if resp.JSON200.DisabledGroups != nil { groupNames = strings.Join(*resp.JSON200.DisabledGroups, "; ") } + if resp.JSON200.AutoEnableInSec == nil || *resp.JSON200.AutoEnableInSec == 0 { log.Log().Infof("blocking disabled for groups: %s", groupNames) } else { diff --git a/config/migration/migration.go b/config/migration/migration.go index af4b8985..3022264f 100644 --- a/config/migration/migration.go +++ b/config/migration/migration.go @@ -102,6 +102,7 @@ func Apply[T any](dest *Dest, apply func(oldValue T)) Migrator { return newMigrator(dest, func(oldName string, oldValue reflect.Value) { valItf := oldValue.Interface() valTyped, ok := valItf.(T) + if !ok { panic(fmt.Errorf("%q migration types don't match: cannot convert %v to %T", oldName, valItf, valTyped)) } diff --git a/go.mod b/go.mod index 5258720b..59f07273 100644 --- a/go.mod +++ b/go.mod @@ -118,7 +118,7 @@ require ( github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/golang/mock v1.6.0 // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/google/go-cmp v0.6.0 // indirect + github.com/google/go-cmp v0.6.0 github.com/hashicorp/errwrap v1.1.0 // indirect github.com/huandu/xstrings v1.3.3 // indirect github.com/imdario/mergo v0.3.15 // indirect diff --git a/lists/downloader.go b/lists/downloader.go index d2e964b3..77339f01 100644 --- a/lists/downloader.go +++ b/lists/downloader.go @@ -75,6 +75,7 @@ func (d *httpDownloader) DownloadFile(ctx context.Context, link string) (io.Read return fmt.Errorf("got status code %d", resp.StatusCode) } + var netErr net.Error if errors.As(httpErr, &netErr) && netErr.Timeout() { return &TransientError{inner: netErr} diff --git a/metrics/metrics_event_publisher.go b/metrics/metrics_event_publisher.go index f60e2c13..567b3afb 100644 --- a/metrics/metrics_event_publisher.go +++ b/metrics/metrics_event_publisher.go @@ -63,6 +63,7 @@ func registerBlockingEventListeners() { subscribe(evt.BlockingCacheGroupChanged, func(listType lists.ListCacheType, groupName string, cnt int) { lastListGroupRefresh.Set(float64(time.Now().Unix())) + switch listType { case lists.ListCacheTypeDenylist: denylistCnt.WithLabelValues(groupName).Set(float64(cnt)) diff --git a/resolver/blocking_resolver.go b/resolver/blocking_resolver.go index d9835fd2..57cbea7d 100644 --- a/resolver/blocking_resolver.go +++ b/resolver/blocking_resolver.go @@ -165,7 +165,6 @@ func NewBlockingResolver(ctx context.Context, err = evt.Bus().SubscribeOnce(evt.ApplicationStarted, func(_ ...string) { go res.initFQDNIPCache(ctx) }) - if err != nil { return nil, err } @@ -270,6 +269,7 @@ func (r *BlockingResolver) internalDisableBlocking(ctx context.Context, duration return fmt.Errorf("group '%s' is unknown", g) } } + s.disabledGroups = disableGroups } @@ -283,6 +283,7 @@ func (r *BlockingResolver) internalDisableBlocking(ctx context.Context, duration } else { log.Log().Infof("disable blocking for %s for group(s) '%s'", duration, log.EscapeInput(strings.Join(s.disabledGroups, "; "))) + s.enableTimer = time.AfterFunc(duration, func() { r.EnableBlocking(ctx) log.Log().Info("blocking enabled again") diff --git a/resolver/mocks_test.go b/resolver/mocks_test.go index 3ae046ff..4103ae39 100644 --- a/resolver/mocks_test.go +++ b/resolver/mocks_test.go @@ -173,6 +173,7 @@ func newTestDOHUpstream(fn func(request *dns.Msg) (response *dns.Msg), f(w) } } + _, err = w.Write(b) util.FatalOnError("can't write response: ", err) diff --git a/resolver/query_logging_resolver.go b/resolver/query_logging_resolver.go index 02fc9086..91e880d0 100644 --- a/resolver/query_logging_resolver.go +++ b/resolver/query_logging_resolver.go @@ -38,6 +38,7 @@ func NewQueryLoggingResolver(ctx context.Context, cfg config.QueryLog) *QueryLog err := retry.Do( func() error { var err error + switch cfg.Type { case config.QueryLogTypeCsv: writer, err = querylog.NewCSVWriter(cfg.Target, false, cfg.LogRetentionDays) diff --git a/server/server_endpoints.go b/server/server_endpoints.go index 54f43a12..0302ab74 100644 --- a/server/server_endpoints.go +++ b/server/server_endpoints.go @@ -226,7 +226,9 @@ func configureStaticAssetsHandler(router *chi.Mux) { func configureRootHandler(cfg *config.Config, router *chi.Mux) { router.Get("/", func(writer http.ResponseWriter, request *http.Request) { writer.Header().Set(contentTypeHeader, htmlContentType) + t := template.New("index") + _, _ = t.Parse(web.IndexTmpl) type HandlerLink struct { @@ -239,11 +241,13 @@ func configureRootHandler(cfg *config.Config, router *chi.Mux) { Version string BuildTime string } + pd := PageData{ Links: nil, Version: util.Version, BuildTime: util.BuildTime, } + pd.Links = []HandlerLink{ { URL: "/docs/openapi.yaml",