zones: introduce ScanOption/ScanOptions for New()/NewFS()

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-28 15:35:37 +00:00
parent 1655ce85bc
commit 9af88f6593
3 changed files with 71 additions and 43 deletions
+8 -8
View File
@@ -5,15 +5,15 @@ import (
"sort"
)
func (m *Zones) scan() error {
for _, fn := range []func() error{
func (m *Zones) scan(opts *ScanOptions) error {
for _, fn := range []func(*ScanOptions) error{
m.scanDirectory,
m.scanMachines,
m.scanZoneIDs,
m.scanSort,
m.scanGateways,
} {
if err := fn(); err != nil {
if err := fn(opts); err != nil {
return err
}
}
@@ -21,7 +21,7 @@ func (m *Zones) scan() error {
return nil
}
func (m *Zones) scanDirectory() error {
func (m *Zones) scanDirectory(_ *ScanOptions) error {
// each directory is a zone
entries, err := fs.ReadDir(m.dir, ".")
if err != nil {
@@ -46,7 +46,7 @@ func (m *Zones) scanDirectory() error {
return nil
}
func (m *Zones) scanMachines() error {
func (m *Zones) scanMachines(_ *ScanOptions) error {
var err error
m.ForEachMachine(func(p *Machine) bool {
err = p.scan()
@@ -55,7 +55,7 @@ func (m *Zones) scanMachines() error {
return err
}
func (m *Zones) scanZoneIDs() error {
func (m *Zones) scanZoneIDs(_ *ScanOptions) error {
var hasMissing bool
var lastZoneID int
@@ -85,7 +85,7 @@ func (m *Zones) scanZoneIDs() error {
return nil
}
func (m *Zones) scanSort() error {
func (m *Zones) scanSort(_ *ScanOptions) error {
sort.SliceStable(m.Zones, func(i, j int) bool {
id1 := m.Zones[i].ID
id2 := m.Zones[j].ID
@@ -111,7 +111,7 @@ func (m *Zones) scanSort() error {
return nil
}
func (m *Zones) scanGateways() error {
func (m *Zones) scanGateways(_ *ScanOptions) error {
var err error
m.ForEachZone(func(z *Zone) bool {