Files
tendrils/config.go

41 lines
722 B
Go
Raw Normal View History

2026-01-24 15:04:42 -08:00
package tendrils
import (
"encoding/json"
"os"
"gopkg.in/yaml.v3"
)
type Config struct {
Locations []*Location `yaml:"locations" json:"locations"`
2026-01-24 15:04:42 -08:00
}
type Location struct {
Name string `yaml:"name" json:"name"`
Nodes []string `yaml:"nodes,omitempty" json:"nodes,omitempty"`
Children []*Location `yaml:"children,omitempty" json:"children,omitempty"`
2026-01-24 15:04:42 -08:00
}
func LoadConfig(path string) (*Config, error) {
if path == "" {
return &Config{}, nil
}
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}
var cfg Config
if err := yaml.Unmarshal(data, &cfg); err != nil {
return nil, err
}
return &cfg, nil
}
func (c *Config) ToJSON() ([]byte, error) {
return json.Marshal(c)
}