From 0d2e181a4ed6ab7f015a449e4b079abdb7f57a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Cluseau?= Date: Mon, 15 Apr 2024 13:47:50 +0200 Subject: [PATCH] host templates in localconfig --- localconfig/localconfig.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/localconfig/localconfig.go b/localconfig/localconfig.go index ed2840c..6e2494d 100644 --- a/localconfig/localconfig.go +++ b/localconfig/localconfig.go @@ -2,16 +2,17 @@ package localconfig import ( "io" - "io/ioutil" + "os" "strings" yaml "gopkg.in/yaml.v2" ) type Config struct { - Clusters []*Cluster - Hosts []*Host - SSLConfig string + Clusters []*Cluster + Hosts []*Host + HostTemplates []*Host + SSLConfig string } type Cluster struct { @@ -29,7 +30,7 @@ func FromBytes(data []byte) (*Config, error) { } func FromFile(path string) (*Config, error) { - ba, err := ioutil.ReadFile(path) + ba, err := os.ReadFile(path) if err != nil { return nil, err } @@ -68,6 +69,15 @@ func (c *Config) Host(name string) *Host { return nil } +func (c *Config) HostTemplate(name string) *Host { + for _, host := range c.HostTemplates { + if host.Name == name { + return host + } + } + return nil +} + func (c *Config) HostByIP(ip string) *Host { for _, host := range c.Hosts { for _, hostIP := range host.IPs {