Rename strutil to stringsx, use wg.Go
Address PR review feedback: rename the shared string-helper package from strutil to stringsx to avoid the discouraged util suffix and the collision with the standard strings package, updating all import paths and call sites. Replace the manual wg.Add/wg.Done bookkeeping in the enrichment worker with wg.Go, which is less error-prone. Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
@@ -28,7 +28,7 @@ import (
|
||||
"go.probo.inc/probo/pkg/coredata"
|
||||
"go.probo.inc/probo/pkg/gid"
|
||||
"go.probo.inc/probo/pkg/llm"
|
||||
"go.probo.inc/probo/pkg/strutil"
|
||||
"go.probo.inc/probo/pkg/stringsx"
|
||||
"go.probo.inc/probo/pkg/thirdparty"
|
||||
"go.probo.inc/probo/pkg/uri"
|
||||
)
|
||||
@@ -716,15 +716,15 @@ func nameMatchesSiteDomain(name, siteOrigin string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
normalizedName := strutil.NormalizeAlnum(name)
|
||||
normalizedName := stringsx.NormalizeAlnum(name)
|
||||
if normalizedName == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
label, _, _ := strings.Cut(domain, ".")
|
||||
|
||||
return normalizedName == strutil.NormalizeAlnum(domain) ||
|
||||
normalizedName == strutil.NormalizeAlnum(label)
|
||||
return normalizedName == stringsx.NormalizeAlnum(domain) ||
|
||||
normalizedName == stringsx.NormalizeAlnum(label)
|
||||
}
|
||||
|
||||
// cookieDatabaseAggregators holds alphanumeric-normalised names of pure
|
||||
@@ -754,11 +754,11 @@ var cookieDatabaseAggregators = map[string]struct{}{
|
||||
// normalised so spacing, punctuation, and casing differences do not
|
||||
// matter.
|
||||
func nameIsCookieDatabaseAggregator(name string) bool {
|
||||
if _, ok := cookieDatabaseAggregators[strutil.NormalizeAlnum(name)]; ok {
|
||||
if _, ok := cookieDatabaseAggregators[stringsx.NormalizeAlnum(name)]; ok {
|
||||
return true
|
||||
}
|
||||
|
||||
label := strutil.NormalizeAlnum(uri.DomainLabel(name))
|
||||
label := stringsx.NormalizeAlnum(uri.DomainLabel(name))
|
||||
if label == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
// Package strutil holds small, dependency-free string helpers shared
|
||||
// Package stringsx holds small, dependency-free string helpers shared
|
||||
// across packages.
|
||||
package strutil
|
||||
package stringsx
|
||||
|
||||
import "strings"
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package strutil_test
|
||||
package stringsx_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.probo.inc/probo/pkg/strutil"
|
||||
"go.probo.inc/probo/pkg/stringsx"
|
||||
)
|
||||
|
||||
func TestNormalizeAlnum(t *testing.T) {
|
||||
@@ -41,7 +41,7 @@ func TestNormalizeAlnum(t *testing.T) {
|
||||
tt.name,
|
||||
func(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert.Equal(t, tt.expected, strutil.NormalizeAlnum(tt.input))
|
||||
assert.Equal(t, tt.expected, stringsx.NormalizeAlnum(tt.input))
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -299,25 +299,17 @@ func (h *enrichmentHandler) Process(ctx context.Context, party coredata.CommonTh
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
wg.Add(3)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
wg.Go(func() {
|
||||
compliance, complianceErr = h.runComplianceDocs(ctx, party.Name, website, legalName)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
})
|
||||
|
||||
wg.Go(func() {
|
||||
domainsResult, domainsErr = h.runDomains(ctx, party.Name, website)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
})
|
||||
|
||||
wg.Go(func() {
|
||||
logoFile = h.prepareLogo(ctx, party, website)
|
||||
}()
|
||||
})
|
||||
|
||||
wg.Wait()
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"go.probo.inc/probo/pkg/strutil"
|
||||
"go.probo.inc/probo/pkg/stringsx"
|
||||
"go.probo.inc/probo/pkg/uri"
|
||||
)
|
||||
|
||||
@@ -158,7 +158,7 @@ func vendorLabels(name, website string) []string {
|
||||
}
|
||||
|
||||
add(uri.DomainLabel(website))
|
||||
add(strutil.NormalizeAlnum(name))
|
||||
add(stringsx.NormalizeAlnum(name))
|
||||
|
||||
return labels
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user