Cleanup / audit

This commit is contained in:
jdl
2026-06-25 13:35:41 +02:00
parent 9a0beaf9cb
commit 58adb4b2a6
8 changed files with 49 additions and 25 deletions

View File

@@ -1,9 +1,11 @@
package sqlgen
import (
"bytes"
_ "embed"
"fmt"
"go/format"
"os"
"os/exec"
"path/filepath"
"text/template"
)
@@ -22,13 +24,9 @@ func render(driver, schemaPath, outputPath string) (err error) {
}
tmpl := template.Must(template.New("").Parse(fileTemplate))
fOut, err := os.Create(outputPath)
if err != nil {
return err
}
defer fOut.Close()
err = tmpl.Execute(fOut, struct {
buf := &bytes.Buffer{}
err = tmpl.Execute(buf, struct {
PackageName string
Schema *schema
}{filepath.Base(filepath.Dir(outputPath)), sch})
@@ -36,5 +34,10 @@ func render(driver, schemaPath, outputPath string) (err error) {
return err
}
return exec.Command("gofmt", "-w", outputPath).Run()
formatted, err := format.Source(buf.Bytes())
if err != nil {
return fmt.Errorf("formatting generated code: %w", err)
}
return os.WriteFile(outputPath, formatted, 0o644)
}