Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e7c5f7094 | |||
| 68966dd9ad |
@@ -1,7 +0,0 @@
|
|||||||
package zones
|
|
||||||
|
|
||||||
// A Machine is a machine on a Zone
|
|
||||||
type Machine struct {
|
|
||||||
zone *Zone
|
|
||||||
name string
|
|
||||||
}
|
|
||||||
+1
-25
@@ -1,29 +1,5 @@
|
|||||||
package zones
|
package zones
|
||||||
|
|
||||||
import (
|
func (*Zones) Scan() error {
|
||||||
"io/fs"
|
|
||||||
"log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (m *Zones) scan() error {
|
|
||||||
var zones []Zone
|
|
||||||
|
|
||||||
// each directory is a zone
|
|
||||||
entries, err := fs.ReadDir(m.dir, ".")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, e := range entries {
|
|
||||||
if e.IsDir() {
|
|
||||||
z := Zone{
|
|
||||||
zones: m,
|
|
||||||
name: e.Name(),
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Print(z)
|
|
||||||
zones = append(zones, z)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-26
@@ -1,39 +1,17 @@
|
|||||||
package zones
|
package zones
|
||||||
|
|
||||||
import (
|
|
||||||
"io/fs"
|
|
||||||
"os"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Zone represents one zone in a cluster
|
|
||||||
type Zone struct {
|
|
||||||
zones *Zones
|
|
||||||
|
|
||||||
id int
|
|
||||||
name string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Zones represents all zones in a cluster
|
|
||||||
type Zones struct {
|
type Zones struct {
|
||||||
dir fs.FS
|
basedir string
|
||||||
|
|
||||||
zones []Zone
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFS builds a [Zones] tree using the given directory
|
func New(dir string) (*Zones, error) {
|
||||||
func NewFS(dir fs.FS) (*Zones, error) {
|
|
||||||
z := &Zones{
|
z := &Zones{
|
||||||
dir: dir,
|
basedir: dir,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := z.scan(); err != nil {
|
if err := z.Scan(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return z, nil
|
return z, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// New builds a [Zones] tree using the given directory
|
|
||||||
func New(dir string) (*Zones, error) {
|
|
||||||
return NewFS(os.DirFS(dir))
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user