[go-fan] Go Module Review: go-yaml #5183
Closed
Replies: 1 comment
-
|
⚓ Avast! This discussion be marked as outdated by Go Fan. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
🐹 Go Fan Report: github.com/goccy/go-yaml
Module Overview
goccy/go-yamlis a modern, high-performance YAML parser for Go that was written from scratch to replace the legacygo-yaml/yamllibrary. It's the backbone of gh-aw's GitHub Actions workflow compilation system, providing better parsing capabilities, reversible transformations with comments/anchors, and fullencoding/jsonbehavior compatibility.Key Features:
Current Usage in gh-aw
The module is extensively used throughout the workflow compilation pipeline:
pkg/workflow/andpkg/cli/yaml.Unmarshal()- Standard unmarshalingyaml.Marshal()/yaml.MarshalWithOptions()- Custom marshaling with field orderingyaml.MapSlice/yaml.MapItem- Ordered maps for GitHub Actions field orderyaml.Indent(),yaml.UseLiteralStyleIfMultiline()- GitHub Actions formattingUsage Highlights
1. Custom Field Ordering (pkg/workflow/yaml.go:42)
2. Schema Validation (pkg/workflow/schema_validation.go:94)
3. Frontmatter Extraction (pkg/workflow/frontmatter_extraction.go:73)
Research Findings
Repository Analysis
Recent Updates (v1.19.0)
The latest version includes several valuable improvements:
yaml.RawMessagesimilar tojson.RawMessagefor deferred decodingBest Practices from Maintainers
yaml.Indent(2)andyaml.UseLiteralStyleIfMultiline(true)are recommendedfmt.Errorfanytype for JSON Schema validationPathString()for extracting specific valuesImprovement Opportunities
🏃 Quick Wins (High Impact, Low Effort)
1. Upgrade to v1.19.0
Impact: Low-risk upgrade with new features
Action: Update
go.modfrom v1.18.0 to v1.19.02. Add Strict Mode Decoding
Impact: Catch typos and unknown fields early
yaml.Strict()option to detect unknown fieldsExample:
Locations: Schema validation, workflow parsing, lock file parsing
3. Enable Colored Error Output
Impact: Better error visibility for developers
yaml.FormatError()for enhanced error messagesExample:
4. Centralize YAML Encoding Options
Impact: DRY principle, consistent formatting
MarshalWithOptionscalls with same optionsExample:
Locations: yaml.go, compiler.go, frontmatter_extraction.go, agentic_engine.go
✨ Feature Opportunities (Medium Impact, Medium Effort)
5. Use yaml.RawMessage for Deferred Decoding (v1.19.0+)
Impact: Performance and flexibility
json.RawMessagepatternExample:
6. Use YAMLPath for Value Extraction
Impact: More concise, less error-prone code
Example:
Locations: frontmatter_extraction.go, schema_validation.go
7. Leverage Decoder Options
Impact: Better control over parsing
yaml.NewDecoder()with custom optionsyaml.ReferenceDirs()for anchor resolution across filesExample:
8. Implement Comment Preservation
Impact: Human-readable workflow files
yaml.CommentToMap()to preserve comments📐 Best Practice Alignment (Code Quality)
9. Audit and Fix Error Handling Patterns
Issue: Inconsistent error handling in compiler.go
if err == nilchecks suggest potential silent error ignoringExample Issue (compiler.go):
Recommended Pattern:
Locations: compiler.go (multiple instances)
10. Document MapSlice Usage
Impact: Better code maintainability
Example:
11. Use Encoder for Large Workflows
Impact: Memory efficiency
yaml.NewEncoder()for streamingMarshalfor large filesExample:
12. Validate YAML Before Schema Validation
Impact: Better error messages
yaml.Validate()to check YAML syntax firstExample:
🔧 General Improvements (Long-term)
13. Consider AST Manipulation for Advanced Cases
Use Cases:
When to Use: When string manipulation isn't sufficient
14. Add YAML Benchmarks
Purpose:
15. Custom Marshalers for Workflow Types
Impact: Better control over output format
Example:
Recommendations
Priority 1 (Immediate - This Week)
Priority 2 (Short-term - Next Sprint)
Priority 3 (Long-term - Future Iterations)
Next Steps
Create PR to upgrade to v1.19.0
go.mod:go get github.com/goccy/go-yaml@v1.19.0Add yaml.Strict() to critical paths
Refactor error handling in compiler.go
if err == nilpatterns to explicit error handlingCreate shared YAML options function
MarshalWithOptionscallsAdd benchmarks for YAML operations
Module summary saved to:
specs/mods/go-yaml.mdReferences:
Beta Was this translation helpful? Give feedback.
All reactions