zones: add resolver and domain

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2023-08-21 21:30:12 +00:00
parent 1b9ce9f688
commit ee63e80f77
5 changed files with 25 additions and 8 deletions
+11 -5
View File
@@ -4,6 +4,8 @@ package zones
import (
"io/fs"
"os"
"darvaza.org/resolver"
)
// Zone represents one zone in a cluster
@@ -22,15 +24,19 @@ func (z *Zone) String() string {
// Zones represents all zones in a cluster
type Zones struct {
dir fs.FS
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) (*Zones, error) {
func NewFS(dir fs.FS, domain string) (*Zones, error) {
z := &Zones{
dir: dir,
dir: dir,
resolver: resolver.SystemResolver(true),
domain: domain,
}
if err := z.scan(); err != nil {
@@ -41,6 +47,6 @@ func NewFS(dir fs.FS) (*Zones, error) {
}
// New builds a [Zones] tree using the given directory
func New(dir string) (*Zones, error) {
return NewFS(os.DirFS(dir))
func New(dir, domain string) (*Zones, error) {
return NewFS(os.DirFS(dir), domain)
}