From bede4160848da4664b4360089a05a29ca4ade725 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Wed, 4 Feb 2026 18:12:16 +0100 Subject: [PATCH] config: refactor template arguments for less duplication --- cmd/safcm/config/templates.go | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/cmd/safcm/config/templates.go b/cmd/safcm/config/templates.go index 52d40dc..2b7508c 100644 --- a/cmd/safcm/config/templates.go +++ b/cmd/safcm/config/templates.go @@ -38,17 +38,20 @@ func LoadTemplates(group string, files map[string]*safcm.File, return fmt.Errorf("%s: failed to load: %v", path, err) } - groupsMap := make(map[string]bool) + defArgs := templateArgs{ + groups: make(map[string]bool), + allHosts: make(map[string]bool), + allGroups: make(map[string]bool), + allGroupHosts: allGroups, + } for _, x := range groups { - groupsMap[x] = true + defArgs.groups[x] = true } - allHostsMap := make(map[string]bool) for x := range allHosts.Map { - allHostsMap[x] = true + defArgs.allHosts[x] = true } - allGroupsMap := make(map[string]bool) for x := range allGroups { - allGroupsMap[x] = true + defArgs.allGroups[x] = true } for _, x := range templates { @@ -68,14 +71,10 @@ func LoadTemplates(group string, files map[string]*safcm.File, if err != nil { return fmt.Errorf("%s: invalid %v", path, err) } - err = tmpl.Execute(&buf, &templateArgs{ - Host: host, - Hostname: strings.Split(host, ".")[0], - groups: groupsMap, - allHosts: allHostsMap, - allGroups: allGroupsMap, - allGroupHosts: allGroups, - }) + args := defArgs + args.Host = host + args.Hostname = strings.Split(host, ".")[0] + err = tmpl.Execute(&buf, &args) if err != nil { return fmt.Errorf("%s: %v", path, err) } -- 2.55.0