Add comprehensive package-level go:tag documentation and API functions#223
Add comprehensive package-level go:tag documentation and API functions#223
go:tag documentation and API functions#223Conversation
Co-authored-by: widmogrod <164249+widmogrod@users.noreply.github.com>
Co-authored-by: widmogrod <164249+widmogrod@users.noreply.github.com>
…d tests Co-authored-by: widmogrod <164249+widmogrod@users.noreply.github.com>
go:tag metadatago:tag documentation and API functions
|
@copilot how some of those APIs and examples would work when static binary would be build and run in clean directory. hape.ExtractPackageTagsFromDir("./mypackage") or shape.ExtractPackageTagsFromFile("main.go") will not have access to files. This is fine for binaries like mkunion that works on golang source files. But when I want a binnary to self reflect on tags that it was compiled, there is no API for that. |
You're absolutely right! The current APIs I added (ExtractPackageTagsFromFile and ExtractPackageTagsFromDir) require access to source files, which won't be available when a static binary runs in a clean directory. I'll implement a solution that embeds package tags at compile-time into the generated type registry, allowing binaries to self-reflect on their package tags without needing source files. Working on this now. |
Co-authored-by: widmogrod <164249+widmogrod@users.noreply.github.com>
Co-authored-by: widmogrod <164249+widmogrod@users.noreply.github.com>
Co-authored-by: widmogrod <164249+widmogrod@users.noreply.github.com>
cmd/mkunion/mkunion
Outdated
There was a problem hiding this comment.
@copilot binary file cannot be commited
There was a problem hiding this comment.
Fixed in commit 47b5f20. Removed the binary file and added better .gitignore patterns to prevent this from happening again.
Co-authored-by: widmogrod <164249+widmogrod@users.noreply.github.com>
You're absolutely right! I implemented a solution that embeds package tags at compile-time into the generated type registry, allowing binaries to self-reflect on their package tags without needing source files. The runtime API functions work as follows: // For package-specific tags (most common use case)
tags := shape.GetRuntimePackageTags("github.com/myorg/pkg")
version := shape.GetRuntimePackageTagValue("github.com/myorg/pkg", "version", "unknown")
// For tags across all packages
tags := shape.GetRuntimePackageTagsAll()
version := shape.GetRuntimePackageTagValueAll("version", "unknown")This allows static binaries to access their compile-time package metadata at runtime, solving the limitation you identified. See the working example in |
This PR addresses the issue "docs: describe that go:tag can be used on package level feature: expose functions to extract
go:tagmetadata" by providing comprehensive documentation and convenient API functions for package-levelgo:tagusage.Problem
While mkunion already supported package-level
go:tagannotations internally, this functionality was not well-documented and lacked convenient API functions for extraction and manipulation of package-level tag metadata.Solution
📚 Documentation
docs/package_tags.mdcovering syntax, built-in tags, custom tags, and best practicesREADME.mdwith package-level tag examplesexample/package_tags/demonstrating real-world usage🛠️ API Functions
Added four new convenience functions to the
shapepackage:Package-Level Tag Examples
The implementation supports powerful package-level configuration:
Use Cases
Testing
Backward Compatibility
This change is fully backward compatible. All existing functionality continues to work unchanged, while the new API functions provide additional convenience for working with package-level tags.
The existing
IndexedTypeWalker.PackageTags()method continues to work as before, and the new functions provide alternative approaches for different use cases.💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.