|
|
|
@ -73,7 +73,7 @@ func WithLogger(log slog.Logger) ScanOption {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *Cluster) setDefaults(opt *ScanOptions) error { |
|
|
|
|
func (m *Cluster) setScanDefaults(opt *ScanOptions) error { |
|
|
|
|
if m.resolver == nil { |
|
|
|
|
h := DefaultLookuper() |
|
|
|
|
|
|
|
|
@ -91,43 +91,41 @@ func (m *Cluster) setDefaults(opt *ScanOptions) error {
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewFS builds a [Cluster] tree using the given directory
|
|
|
|
|
func NewFS(dir fs.FS, domain string, opts ...ScanOption) (*Cluster, error) { |
|
|
|
|
// NewFromDirectory builds a [Cluster] tree using the given directory
|
|
|
|
|
func NewFromDirectory(dir, domain string, opts ...ScanOption) (*Cluster, error) { |
|
|
|
|
var scanOptions ScanOptions |
|
|
|
|
|
|
|
|
|
z := &Cluster{ |
|
|
|
|
dir: dir, |
|
|
|
|
domain: domain, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, opt := range opts { |
|
|
|
|
if err := opt(z, &scanOptions); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
dir = filepath.Clean(dir) |
|
|
|
|
fullPath, err := filepath.Abs(dir) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err := z.setDefaults(&scanOptions); err != nil { |
|
|
|
|
sub, err := os.NewFS().Sub(fullPath[1:]) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err := z.scan(&scanOptions); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
m := &Cluster{ |
|
|
|
|
dir: sub, |
|
|
|
|
BaseDir: dir, |
|
|
|
|
Name: filepath.Base(fullPath), |
|
|
|
|
Domain: domain, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return z, nil |
|
|
|
|
} |
|
|
|
|
for _, opt := range opts { |
|
|
|
|
if err := opt(m, &scanOptions); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// New builds a [Cluster] tree using the given directory
|
|
|
|
|
func New(dir, domain string, opts ...ScanOption) (*Cluster, error) { |
|
|
|
|
dir, err := filepath.Abs(dir) |
|
|
|
|
if err != nil { |
|
|
|
|
if err := m.setScanDefaults(&scanOptions); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
base, err := os.NewFS().Sub(dir[1:]) |
|
|
|
|
if err != nil { |
|
|
|
|
if err := m.scan(&scanOptions); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return NewFS(base, domain, opts...) |
|
|
|
|
return m, nil |
|
|
|
|
} |
|
|
|
|