all: imp code

This commit is contained in:
Stanislav Chzhen 2024-10-07 16:41:58 +03:00
parent 038bae59d5
commit de774009aa
4 changed files with 9 additions and 7 deletions

View file

@ -26,8 +26,8 @@ import (
// Attribute keys and values for logging.
const (
LogPrefix = "safesearch"
LogKey = "client"
LogPrefix = "safesearch"
LogKeyClient = "client"
)
// Service is a enum with service names used as search providers.
@ -106,7 +106,8 @@ type Default struct {
cacheTTL time.Duration
}
// NewDefault returns an initialized default safe search filter.
// NewDefault returns an initialized default safe search filter. ctx is used
// to log the initial refresh.
func NewDefault(ctx context.Context, conf *DefaultConfig) (ss *Default, err error) {
ss = &Default{
logger: conf.Logger,
@ -118,6 +119,7 @@ func NewDefault(ctx context.Context, conf *DefaultConfig) (ss *Default, err erro
cacheTTL: conf.CacheTTL,
}
// TODO(s.chzhen): Move to [Default.InitialRefresh].
err = ss.resetEngine(ctx, rulelist.URLFilterIDSafeSearch, conf.ServicesConfig)
if err != nil {
// Don't wrap the error, because it's informative enough as is.

View file

@ -216,7 +216,7 @@ func (o *clientObject) toPersistent(
if o.SafeSearchConf.Enabled {
logger := baseLogger.With(
slogutil.KeyPrefix, safesearch.LogPrefix,
safesearch.LogKey, cli.Name,
safesearch.LogKeyClient, cli.Name,
)
var ss *safesearch.Default
ss, err = safesearch.NewDefault(ctx, &safesearch.DefaultConfig{

View file

@ -213,7 +213,7 @@ func (clients *clientsContainer) jsonToClient(
if c.SafeSearchConf.Enabled {
logger := clients.baseLogger.With(
slogutil.KeyPrefix, safesearch.LogPrefix,
safesearch.LogKey, c.Name,
safesearch.LogKeyClient, c.Name,
)
var ss *safesearch.Default
ss, err = safesearch.NewDefault(ctx, &safesearch.DefaultConfig{

View file

@ -108,9 +108,9 @@ func assertPersistentClients(tb testing.TB, clients *clientsContainer, want []*c
require.NoError(tb, err)
var got []*client.Persistent
ctx := testutil.ContextWithTimeout(tb, testTimeout)
for _, cj := range clientList.Clients {
var c *client.Persistent
ctx := testutil.ContextWithTimeout(tb, testTimeout)
c, err = clients.jsonToClient(ctx, *cj, nil)
require.NoError(tb, err)
@ -131,10 +131,10 @@ func assertPersistentClientsData(
tb.Helper()
var got []*client.Persistent
ctx := testutil.ContextWithTimeout(tb, testTimeout)
for _, cm := range data {
for _, cj := range cm {
var c *client.Persistent
ctx := testutil.ContextWithTimeout(tb, testTimeout)
c, err := clients.jsonToClient(ctx, *cj, nil)
require.NoError(tb, err)