Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c9f2d03dc5 | |||
| 927810fa24 | |||
| 44ea514e15 |
@@ -0,0 +1,7 @@
|
|||||||
|
package zones
|
||||||
|
|
||||||
|
// A Machine is a machine on a Zone
|
||||||
|
type Machine struct {
|
||||||
|
zone *Zone
|
||||||
|
name string
|
||||||
|
}
|
||||||
+25
-1
@@ -1,5 +1,29 @@
|
|||||||
package zones
|
package zones
|
||||||
|
|
||||||
func (*Zones) Scan() error {
|
import (
|
||||||
|
"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
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-5
@@ -1,17 +1,39 @@
|
|||||||
package zones
|
package zones
|
||||||
|
|
||||||
type Zones struct {
|
import (
|
||||||
basedir string
|
"io/fs"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Zone represents one zone in a cluster
|
||||||
|
type Zone struct {
|
||||||
|
zones *Zones
|
||||||
|
|
||||||
|
id int
|
||||||
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(dir string) (*Zones, error) {
|
// Zones represents all zones in a cluster
|
||||||
|
type Zones struct {
|
||||||
|
dir fs.FS
|
||||||
|
|
||||||
|
zones []Zone
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFS builds a [Zones] tree using the given directory
|
||||||
|
func NewFS(dir fs.FS) (*Zones, error) {
|
||||||
z := &Zones{
|
z := &Zones{
|
||||||
basedir: dir,
|
dir: 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