Browse Source

cluster: group default option factories

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/18/head
Alejandro Mery 1 year ago
parent
commit
2a2e6c121e
  1. 5
      pkg/cluster/cluster_scan_options.go
  2. 17
      pkg/cluster/defaults.go

5
pkg/cluster/cluster_scan_options.go

@ -6,7 +6,6 @@ import (
"darvaza.org/resolver"
"darvaza.org/slog"
"darvaza.org/slog/handlers/discard"
"github.com/hack-pad/hackpadfs/os"
)
@ -65,7 +64,7 @@ func WithResolver(h resolver.Resolver) ScanOption {
func WithLogger(log slog.Logger) ScanOption {
return func(m *Cluster, opt *ScanOptions) error {
if log == nil {
log = discard.New()
log = DefaultLogger()
}
opt.Logger = log
@ -76,7 +75,7 @@ func WithLogger(log slog.Logger) ScanOption {
func (m *Cluster) setDefaults(opt *ScanOptions) error {
if m.resolver == nil {
h := resolver.NewCloudflareLookuper()
h := DefaultLookuper()
if err := WithLookuper(h)(m, opt); err != nil {
return err

17
pkg/cluster/defaults.go

@ -0,0 +1,17 @@
package cluster
import (
"darvaza.org/resolver"
"darvaza.org/slog"
"darvaza.org/slog/handlers/discard"
)
// DefaultLogger returns a logger that doesn't log anything
func DefaultLogger() slog.Logger {
return discard.New()
}
// DefaultLookuper returns a [resolver.Lookuper] using Cloudflare's 1.1.1.1
func DefaultLookuper() resolver.Lookuper {
return resolver.NewCloudflareLookuper()
}
Loading…
Cancel
Save