]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
config: refactor template arguments for less duplication
authorSimon Ruderich <simon.ruderich@fau.de>
Wed, 4 Feb 2026 17:12:16 +0000 (18:12 +0100)
committerSimon Ruderich <simon.ruderich@fau.de>
Wed, 4 Feb 2026 17:12:16 +0000 (18:12 +0100)
cmd/safcm/config/templates.go

index 52d40dc302ec57737e567f66bcc5f24bfd25d515..2b7508c1309f2c7063f45d4f603b0b02ed3fe5a2 100644 (file)
@@ -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)
                }