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

@ -27,7 +27,7 @@ import (
// Attribute keys and values for logging. // Attribute keys and values for logging.
const ( const (
LogPrefix = "safesearch" LogPrefix = "safesearch"
LogKey = "client" LogKeyClient = "client"
) )
// Service is a enum with service names used as search providers. // Service is a enum with service names used as search providers.
@ -106,7 +106,8 @@ type Default struct {
cacheTTL time.Duration 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) { func NewDefault(ctx context.Context, conf *DefaultConfig) (ss *Default, err error) {
ss = &Default{ ss = &Default{
logger: conf.Logger, logger: conf.Logger,
@ -118,6 +119,7 @@ func NewDefault(ctx context.Context, conf *DefaultConfig) (ss *Default, err erro
cacheTTL: conf.CacheTTL, cacheTTL: conf.CacheTTL,
} }
// TODO(s.chzhen): Move to [Default.InitialRefresh].
err = ss.resetEngine(ctx, rulelist.URLFilterIDSafeSearch, conf.ServicesConfig) err = ss.resetEngine(ctx, rulelist.URLFilterIDSafeSearch, conf.ServicesConfig)
if err != nil { if err != nil {
// Don't wrap the error, because it's informative enough as is. // 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 { if o.SafeSearchConf.Enabled {
logger := baseLogger.With( logger := baseLogger.With(
slogutil.KeyPrefix, safesearch.LogPrefix, slogutil.KeyPrefix, safesearch.LogPrefix,
safesearch.LogKey, cli.Name, safesearch.LogKeyClient, cli.Name,
) )
var ss *safesearch.Default var ss *safesearch.Default
ss, err = safesearch.NewDefault(ctx, &safesearch.DefaultConfig{ ss, err = safesearch.NewDefault(ctx, &safesearch.DefaultConfig{

View file

@ -213,7 +213,7 @@ func (clients *clientsContainer) jsonToClient(
if c.SafeSearchConf.Enabled { if c.SafeSearchConf.Enabled {
logger := clients.baseLogger.With( logger := clients.baseLogger.With(
slogutil.KeyPrefix, safesearch.LogPrefix, slogutil.KeyPrefix, safesearch.LogPrefix,
safesearch.LogKey, c.Name, safesearch.LogKeyClient, c.Name,
) )
var ss *safesearch.Default var ss *safesearch.Default
ss, err = safesearch.NewDefault(ctx, &safesearch.DefaultConfig{ 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) require.NoError(tb, err)
var got []*client.Persistent var got []*client.Persistent
ctx := testutil.ContextWithTimeout(tb, testTimeout)
for _, cj := range clientList.Clients { for _, cj := range clientList.Clients {
var c *client.Persistent var c *client.Persistent
ctx := testutil.ContextWithTimeout(tb, testTimeout)
c, err = clients.jsonToClient(ctx, *cj, nil) c, err = clients.jsonToClient(ctx, *cj, nil)
require.NoError(tb, err) require.NoError(tb, err)
@ -131,10 +131,10 @@ func assertPersistentClientsData(
tb.Helper() tb.Helper()
var got []*client.Persistent var got []*client.Persistent
ctx := testutil.ContextWithTimeout(tb, testTimeout)
for _, cm := range data { for _, cm := range data {
for _, cj := range cm { for _, cj := range cm {
var c *client.Persistent var c *client.Persistent
ctx := testutil.ContextWithTimeout(tb, testTimeout)
c, err := clients.jsonToClient(ctx, *cj, nil) c, err := clients.jsonToClient(ctx, *cj, nil)
require.NoError(tb, err) require.NoError(tb, err)