You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@przglogo list has always behaved in this way to my knowledge (arguably because it allows, if required, results to be consumed as they become available, instead of needing to wait for the end of the input)
You can easily use the following approach to parse the output (which does wait for all of the output; the alternative would be to connect the stdout of the command to the decoder):
typeModulestruct {
// ...
}
// ...out, err:=exec.Command("go", "list", "-m", "all").Output()
// ...dec:=json.NewDecoder(bytes.NewReader(out))
for {
varmModuleiferr:=dec.Decode(&m); err!=nil {
iferr==io.EOF {
break
}
log.Fatalf("reading go list output: %v", err)
}
// do something with m
}
When
go list -m -u -json all
is issued it produces invalid JSON.What version of Go are you using (
go version
)?go1.11
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?linux/amd64
What did you do?
Created the following two files in a directory.
foo.go:
go.mod:
Issued this from within the directory:
go list -m -u -json all
What did you expect to see?
Anything that could be parsed using the encoding/json package. A JSON array would be nice:
What did you see instead?
which is a concatenation of JSONs and cannot be easily parsed using encoding/json.
The text was updated successfully, but these errors were encountered: