writeFormattedGo executes `tmpl` with `data` as its context to the file `destPath`
(tmpl *template.Template, data any, destPath string)
| 158 | |
| 159 | // writeFormattedGo executes `tmpl` with `data` as its context to the file `destPath` |
| 160 | func writeFormattedGo(tmpl *template.Template, data any, destPath string) error { |
| 161 | out := bytes.NewBuffer([]byte{}) |
| 162 | err := tmpl.Execute(out, data) |
| 163 | if err != nil { |
| 164 | return err |
| 165 | } |
| 166 | code, err := format.Source(out.Bytes()) |
| 167 | if err != nil { |
| 168 | return err |
| 169 | } |
| 170 | |
| 171 | err = os.WriteFile(destPath, code, 0644) |
| 172 | if err != nil { |
| 173 | return err |
| 174 | } |
| 175 | |
| 176 | return nil |
| 177 | } |
| 178 | |
| 179 | // preserveLegacyCatalogBehavior maintain previous ordering and filtering |
| 180 | // that was manually done to the generated file pg_catalog.go. |