-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: get go list context function formatted as json #27915
Comments
|
@xuruiray that's unrelated to this issue. When |
We can't change the declaration of go/build.Context to have As a workaround, can you extract the fields you need in a convenient format based on a command such as this one?
|
Could you give some more detail on that? We're allowed to add fields, so nobody should be reyling on convertibility anyway (especially given #16085), and we're allowed to add methods, so nobody should be relying on the fact that |
Oh, I forgot that we'd relax the convertibility rules. So then yes, we could add field tags to Context. |
The |
So it does. One possible solution would be to add a "json" function to the set of functions available to the template, that would call json.Marshal on its operand. For example:
|
Since this is the only thing you can't already get as json, maybe it should be a method on that local context type? Like `go list -f '{{context.Json}}' |
In the meantime, here's a workaround that formats BuildTags/ReleaseTags as json as well:
|
The
context
template function available togo list
has some useful data, even after ignoring the overlap withgo env -json
. There's no way to output thecontext
as json, making it hard to use the results programatically.cc: @bcmills @rsc @ianlancetaylor @alandonovan
The text was updated successfully, but these errors were encountered: