* Add lint/format checks to the Gitea release workflow and Makefile (targets: vet, fmt, fmt-check, staticcheck, govulncheck, check) * Switch .golangci.json formatter from gofmt to gofumpt (extra.group-params) * Bump golang.org/x/text 0.37.0 -> 0.39.0 for GO-2026-5970; re-vendor * Fix staticcheck S1011 in pkg/diff; drop unused pgsql writer helpers * Fix gocritic unnamedResult (pkg/diff) and rangeValCopy (pkg/pgsql) * Apply gofumpt + goimports formatting across the tree
65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package yaml
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
"git.warky.dev/wdevs/relspecgo/pkg/models"
|
|
"git.warky.dev/wdevs/relspecgo/pkg/writers"
|
|
)
|
|
|
|
// Writer implements the writers.Writer interface for YAML format
|
|
type Writer struct {
|
|
options *writers.WriterOptions
|
|
}
|
|
|
|
// NewWriter creates a new YAML writer with the given options
|
|
func NewWriter(options *writers.WriterOptions) *Writer {
|
|
return &Writer{
|
|
options: options,
|
|
}
|
|
}
|
|
|
|
// WriteDatabase writes a complete database as YAML
|
|
func (w *Writer) WriteDatabase(db *models.Database) error {
|
|
data, err := yaml.Marshal(db)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to marshal database to YAML: %w", err)
|
|
}
|
|
|
|
return w.writeOutput(data)
|
|
}
|
|
|
|
// WriteSchema writes a schema as YAML
|
|
func (w *Writer) WriteSchema(schema *models.Schema) error {
|
|
data, err := yaml.Marshal(schema)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to marshal schema to YAML: %w", err)
|
|
}
|
|
|
|
return w.writeOutput(data)
|
|
}
|
|
|
|
// WriteTable writes a single table as YAML
|
|
func (w *Writer) WriteTable(table *models.Table) error {
|
|
data, err := yaml.Marshal(table)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to marshal table to YAML: %w", err)
|
|
}
|
|
|
|
return w.writeOutput(data)
|
|
}
|
|
|
|
// writeOutput writes the content to file or stdout
|
|
func (w *Writer) writeOutput(data []byte) error {
|
|
if w.options.OutputPath != "" {
|
|
return os.WriteFile(w.options.OutputPath, data, 0o644)
|
|
}
|
|
|
|
// Print to stdout
|
|
fmt.Println(string(data))
|
|
return nil
|
|
}
|