You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
898 B

// Package zones contains information about the cluster
package zones
import (
"io/fs"
"os"
"darvaza.org/resolver"
)
// Zone represents one zone in a cluster
type Zone struct {
zones *Zones
ID int
Name string
Machines []*Machine `toml:"machines"`
}
func (z *Zone) String() string {
return z.Name
}
// Zones represents all zones in a cluster
type Zones struct {
dir fs.FS
resolver resolver.Resolver
domain string
Zones []*Zone `toml:"zones"`
}
// NewFS builds a [Zones] tree using the given directory
func NewFS(dir fs.FS, domain string) (*Zones, error) {
z := &Zones{
dir: dir,
resolver: resolver.SystemResolver(true),
domain: domain,
}
if err := z.scan(); err != nil {
return nil, err
}
return z, nil
}
// New builds a [Zones] tree using the given directory
func New(dir, domain string) (*Zones, error) {
return NewFS(os.DirFS(dir), domain)
}