Skip to content

Commit

Permalink
Refactoring/linter (#1447)
Browse files Browse the repository at this point in the history
* update golangci-lint to v1.57.2

* linter fixes
  • Loading branch information
kwitsch authored Apr 12, 2024
1 parent 30cda6c commit debac9e
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions cache/stringcache/string_caches.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func (r *wildcardCacheFactory) addEntry(entry string) bool {
entry = normalizeWildcard(entry)

r.trie.Insert(entry)

r.cnt++

return true
Expand Down
1 change: 1 addition & 0 deletions cmd/blocking.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions config/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lists/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
1 change: 1 addition & 0 deletions metrics/metrics_event_publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion resolver/blocking_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -270,6 +269,7 @@ func (r *BlockingResolver) internalDisableBlocking(ctx context.Context, duration
return fmt.Errorf("group '%s' is unknown", g)
}
}

s.disabledGroups = disableGroups
}

Expand All @@ -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")
Expand Down
1 change: 1 addition & 0 deletions resolver/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions resolver/query_logging_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions server/server_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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",
Expand Down

0 comments on commit debac9e

Please sign in to comment.