mirror of https://github.com/0xERR0R/blocky.git
Refactoring/linter (#1447)
* update golangci-lint to v1.57.2 * linter fixes
This commit is contained in:
parent
30cda6c367
commit
debac9eaa8
2
Makefile
2
Makefile
|
@ -23,7 +23,7 @@ GO_BUILD_LD_FLAGS:=\
|
||||||
GO_BUILD_OUTPUT:=$(BIN_OUT_DIR)/$(BINARY_NAME)$(BINARY_SUFFIX)
|
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
|
# 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
|
GINKGO_PROCS?=-p
|
||||||
|
|
||||||
|
|
|
@ -222,6 +222,7 @@ func (r *wildcardCacheFactory) addEntry(entry string) bool {
|
||||||
entry = normalizeWildcard(entry)
|
entry = normalizeWildcard(entry)
|
||||||
|
|
||||||
r.trie.Insert(entry)
|
r.trie.Insert(entry)
|
||||||
|
|
||||||
r.cnt++
|
r.cnt++
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -109,6 +109,7 @@ func statusBlocking(_ *cobra.Command, _ []string) error {
|
||||||
if resp.JSON200.DisabledGroups != nil {
|
if resp.JSON200.DisabledGroups != nil {
|
||||||
groupNames = strings.Join(*resp.JSON200.DisabledGroups, "; ")
|
groupNames = strings.Join(*resp.JSON200.DisabledGroups, "; ")
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.JSON200.AutoEnableInSec == nil || *resp.JSON200.AutoEnableInSec == 0 {
|
if resp.JSON200.AutoEnableInSec == nil || *resp.JSON200.AutoEnableInSec == 0 {
|
||||||
log.Log().Infof("blocking disabled for groups: %s", groupNames)
|
log.Log().Infof("blocking disabled for groups: %s", groupNames)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -102,6 +102,7 @@ func Apply[T any](dest *Dest, apply func(oldValue T)) Migrator {
|
||||||
return newMigrator(dest, func(oldName string, oldValue reflect.Value) {
|
return newMigrator(dest, func(oldName string, oldValue reflect.Value) {
|
||||||
valItf := oldValue.Interface()
|
valItf := oldValue.Interface()
|
||||||
valTyped, ok := valItf.(T)
|
valTyped, ok := valItf.(T)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
panic(fmt.Errorf("%q migration types don't match: cannot convert %v to %T", oldName, valItf, valTyped))
|
panic(fmt.Errorf("%q migration types don't match: cannot convert %v to %T", oldName, valItf, valTyped))
|
||||||
}
|
}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -118,7 +118,7 @@ require (
|
||||||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
|
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
|
||||||
github.com/golang/mock v1.6.0 // indirect
|
github.com/golang/mock v1.6.0 // indirect
|
||||||
github.com/golang/protobuf v1.5.3 // 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/hashicorp/errwrap v1.1.0 // indirect
|
||||||
github.com/huandu/xstrings v1.3.3 // indirect
|
github.com/huandu/xstrings v1.3.3 // indirect
|
||||||
github.com/imdario/mergo v0.3.15 // indirect
|
github.com/imdario/mergo v0.3.15 // indirect
|
||||||
|
|
|
@ -75,6 +75,7 @@ func (d *httpDownloader) DownloadFile(ctx context.Context, link string) (io.Read
|
||||||
|
|
||||||
return fmt.Errorf("got status code %d", resp.StatusCode)
|
return fmt.Errorf("got status code %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
var netErr net.Error
|
var netErr net.Error
|
||||||
if errors.As(httpErr, &netErr) && netErr.Timeout() {
|
if errors.As(httpErr, &netErr) && netErr.Timeout() {
|
||||||
return &TransientError{inner: netErr}
|
return &TransientError{inner: netErr}
|
||||||
|
|
|
@ -63,6 +63,7 @@ func registerBlockingEventListeners() {
|
||||||
|
|
||||||
subscribe(evt.BlockingCacheGroupChanged, func(listType lists.ListCacheType, groupName string, cnt int) {
|
subscribe(evt.BlockingCacheGroupChanged, func(listType lists.ListCacheType, groupName string, cnt int) {
|
||||||
lastListGroupRefresh.Set(float64(time.Now().Unix()))
|
lastListGroupRefresh.Set(float64(time.Now().Unix()))
|
||||||
|
|
||||||
switch listType {
|
switch listType {
|
||||||
case lists.ListCacheTypeDenylist:
|
case lists.ListCacheTypeDenylist:
|
||||||
denylistCnt.WithLabelValues(groupName).Set(float64(cnt))
|
denylistCnt.WithLabelValues(groupName).Set(float64(cnt))
|
||||||
|
|
|
@ -165,7 +165,6 @@ func NewBlockingResolver(ctx context.Context,
|
||||||
err = evt.Bus().SubscribeOnce(evt.ApplicationStarted, func(_ ...string) {
|
err = evt.Bus().SubscribeOnce(evt.ApplicationStarted, func(_ ...string) {
|
||||||
go res.initFQDNIPCache(ctx)
|
go res.initFQDNIPCache(ctx)
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -270,6 +269,7 @@ func (r *BlockingResolver) internalDisableBlocking(ctx context.Context, duration
|
||||||
return fmt.Errorf("group '%s' is unknown", g)
|
return fmt.Errorf("group '%s' is unknown", g)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.disabledGroups = disableGroups
|
s.disabledGroups = disableGroups
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,6 +283,7 @@ func (r *BlockingResolver) internalDisableBlocking(ctx context.Context, duration
|
||||||
} else {
|
} else {
|
||||||
log.Log().Infof("disable blocking for %s for group(s) '%s'", duration,
|
log.Log().Infof("disable blocking for %s for group(s) '%s'", duration,
|
||||||
log.EscapeInput(strings.Join(s.disabledGroups, "; ")))
|
log.EscapeInput(strings.Join(s.disabledGroups, "; ")))
|
||||||
|
|
||||||
s.enableTimer = time.AfterFunc(duration, func() {
|
s.enableTimer = time.AfterFunc(duration, func() {
|
||||||
r.EnableBlocking(ctx)
|
r.EnableBlocking(ctx)
|
||||||
log.Log().Info("blocking enabled again")
|
log.Log().Info("blocking enabled again")
|
||||||
|
|
|
@ -173,6 +173,7 @@ func newTestDOHUpstream(fn func(request *dns.Msg) (response *dns.Msg),
|
||||||
f(w)
|
f(w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = w.Write(b)
|
_, err = w.Write(b)
|
||||||
|
|
||||||
util.FatalOnError("can't write response: ", err)
|
util.FatalOnError("can't write response: ", err)
|
||||||
|
|
|
@ -38,6 +38,7 @@ func NewQueryLoggingResolver(ctx context.Context, cfg config.QueryLog) *QueryLog
|
||||||
err := retry.Do(
|
err := retry.Do(
|
||||||
func() error {
|
func() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
switch cfg.Type {
|
switch cfg.Type {
|
||||||
case config.QueryLogTypeCsv:
|
case config.QueryLogTypeCsv:
|
||||||
writer, err = querylog.NewCSVWriter(cfg.Target, false, cfg.LogRetentionDays)
|
writer, err = querylog.NewCSVWriter(cfg.Target, false, cfg.LogRetentionDays)
|
||||||
|
|
|
@ -226,7 +226,9 @@ func configureStaticAssetsHandler(router *chi.Mux) {
|
||||||
func configureRootHandler(cfg *config.Config, router *chi.Mux) {
|
func configureRootHandler(cfg *config.Config, router *chi.Mux) {
|
||||||
router.Get("/", func(writer http.ResponseWriter, request *http.Request) {
|
router.Get("/", func(writer http.ResponseWriter, request *http.Request) {
|
||||||
writer.Header().Set(contentTypeHeader, htmlContentType)
|
writer.Header().Set(contentTypeHeader, htmlContentType)
|
||||||
|
|
||||||
t := template.New("index")
|
t := template.New("index")
|
||||||
|
|
||||||
_, _ = t.Parse(web.IndexTmpl)
|
_, _ = t.Parse(web.IndexTmpl)
|
||||||
|
|
||||||
type HandlerLink struct {
|
type HandlerLink struct {
|
||||||
|
@ -239,11 +241,13 @@ func configureRootHandler(cfg *config.Config, router *chi.Mux) {
|
||||||
Version string
|
Version string
|
||||||
BuildTime string
|
BuildTime string
|
||||||
}
|
}
|
||||||
|
|
||||||
pd := PageData{
|
pd := PageData{
|
||||||
Links: nil,
|
Links: nil,
|
||||||
Version: util.Version,
|
Version: util.Version,
|
||||||
BuildTime: util.BuildTime,
|
BuildTime: util.BuildTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
pd.Links = []HandlerLink{
|
pd.Links = []HandlerLink{
|
||||||
{
|
{
|
||||||
URL: "/docs/openapi.yaml",
|
URL: "/docs/openapi.yaml",
|
||||||
|
|
Loading…
Reference in New Issue