From ad1bf5cf6edbbdd8030f07c1d8f028005aa8b20d Mon Sep 17 00:00:00 2001 From: Stanislav Chzhen Date: Thu, 29 Jun 2023 19:35:33 +0300 Subject: [PATCH] Pull request 1898: fix-whois-gocognit Squashed commit of the following: commit 69675b742a3b8a1d513f1b5f9c488577ced329b8 Merge: 0d069b769 ee8eb1d8a Author: Stanislav Chzhen Date: Thu Jun 29 19:31:26 2023 +0300 Merge branch 'master' into fix-whois-gocognit commit 0d069b76938d9b3011b8d92865e7630027f1ebd1 Author: Stanislav Chzhen Date: Thu Jun 29 19:21:02 2023 +0300 whois: imp code more commit 6c4ab4a4e0451551bcec5472d997a88989f013e4 Author: Stanislav Chzhen Date: Thu Jun 29 18:08:50 2023 +0300 whois: imp code commit 0d04ddbd6f8bb3848673c3f86fc26dca2fd4d402 Author: Stanislav Chzhen Date: Thu Jun 29 17:47:06 2023 +0300 whois: imp docs commit d7b75f7b42604374cb8cb0aaf141eb5c7fc985d3 Author: Stanislav Chzhen Date: Thu Jun 29 16:54:49 2023 +0300 all: imp code --- internal/whois/whois.go | 16 ++++++++++++++-- scripts/make/go-lint.sh | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/internal/whois/whois.go b/internal/whois/whois.go index e55bcaf7..2a64bdd1 100644 --- a/internal/whois/whois.go +++ b/internal/whois/whois.go @@ -288,6 +288,16 @@ func (w *Default) Process(ctx context.Context, ip netip.Addr) (wi *Info, changed return wi, false } + return w.requestInfo(ctx, ip, wi) +} + +// requestInfo makes WHOIS request and returns WHOIS info. changed is false if +// received information is equal to cached. +func (w *Default) requestInfo( + ctx context.Context, + ip netip.Addr, + cached *Info, +) (wi *Info, changed bool) { var info Info defer func() { @@ -311,12 +321,14 @@ func (w *Default) Process(ctx context.Context, ip netip.Addr) (wi *Info, changed Orgname: kv["orgname"], } + changed = cached == nil || info != *cached + // Don't return an empty struct so that the frontend doesn't get confused. if (info == Info{}) { - return nil, true + return nil, changed } - return &info, wi == nil || info != *wi + return &info, changed } // findInCache finds Info in the cache. expired indicates that Info is valid. diff --git a/scripts/make/go-lint.sh b/scripts/make/go-lint.sh index 09cf981f..3409ed2b 100644 --- a/scripts/make/go-lint.sh +++ b/scripts/make/go-lint.sh @@ -176,9 +176,10 @@ run_linter gocognit --over 10\ ./internal/aghchan/\ ./internal/aghhttp/\ ./internal/aghio/\ - ./internal/tools/\ ./internal/next/\ + ./internal/tools/\ ./internal/version/\ + ./internal/whois/\ ; run_linter ineffassign ./...