MCPcopy
hub / github.com/sqlc-dev/sqlc / writeFormattedGo

Function writeFormattedGo

internal/tools/sqlc-pg-gen/main.go:160–177  ·  view source on GitHub ↗

writeFormattedGo executes `tmpl` with `data` as its context to the file `destPath`

(tmpl *template.Template, data any, destPath string)

Source from the content-addressed store, hash-verified

158
159// writeFormattedGo executes `tmpl` with `data` as its context to the file `destPath`
160func 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.

Callers 1

runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected