| 110 | } |
| 111 | |
| 112 | func saveTemplate(as map[string]*Access, key string) string { |
| 113 | out := make(map[string][]access.Access) |
| 114 | |
| 115 | for _, a := range as { |
| 116 | |
| 117 | out[a.Group] = append(out[a.Group], access.Access{ |
| 118 | Name: a.Name, |
| 119 | CName: a.Cname, |
| 120 | Desc: a.Desc, |
| 121 | }) |
| 122 | } |
| 123 | buf := &bytes.Buffer{} |
| 124 | err := yaml.NewEncoder(buf).Encode(out) |
| 125 | if err != nil { |
| 126 | log.Fatal(err) |
| 127 | return "" |
| 128 | } |
| 129 | filePath := fmt.Sprintf("access.%s.yml", key) |
| 130 | err = os.WriteFile(filePath, buf.Bytes(), 0666) |
| 131 | if err != nil { |
| 132 | log.Fatal(err) |
| 133 | |
| 134 | } |
| 135 | return filePath |
| 136 | } |
| 137 | |
| 138 | type Access struct { |
| 139 | Key string |