generateMessageCodesFile generates the contents of the CODES.md file and returns them.
(filename string, title string)
| 117 | |
| 118 | // generateMessageCodesFile generates the contents of the CODES.md file and returns them. |
| 119 | func generateMessageCodesFile(filename string, title string) (string, error) { |
| 120 | codes, err := getMessageCodes(filename) |
| 121 | if err != nil { |
| 122 | return "", err |
| 123 | } |
| 124 | tpl, err := template.New("CODES.md.tpl").Parse(messageFileTemplate) |
| 125 | if err != nil { |
| 126 | return "", fmt.Errorf("bug: failed to parse template (%w)", err) |
| 127 | } |
| 128 | wr := &bytes.Buffer{} |
| 129 | if err := tpl.Execute(wr, &tplData{ |
| 130 | Title: title, |
| 131 | Codes: codes, |
| 132 | }); err != nil { |
| 133 | return "", fmt.Errorf("failed to render codes template (%w)", err) |
| 134 | } |
| 135 | return wr.String(), nil |
| 136 | } |
| 137 | |
| 138 | // writeMessageCodesFile generates and writes the CODES.md file |
| 139 | func writeMessageCodesFile(data []byte, destinationFile string) error { |
no test coverage detected