Skip to content
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: list -json outputs concatenated JSON documents, not one single one #21280

Closed
stevekuznetsov opened this issue Aug 2, 2017 · 6 comments

Comments

@stevekuznetsov
Copy link

stevekuznetsov commented Aug 2, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

$ go version
go version go1.7.5 linux/amd64

What operating system and processor architecture are you using (go env)?

$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/skuznets/Documents/go"
GORACE=""
GOROOT="/home/skuznets/.gvm/gos/go1.7.5"
GOTOOLDIR="/home/skuznets/.gvm/gos/go1.7.5/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build979771774=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

What did you do?

I ran go list -json on a project with multiple packages.

What did you expect to see?

A JSON list:

{
  "Packages": [
    {
      "Dir": "whatever"
    },
    {
      "Dir": "whatever/else"
    }
  ]
}

What did you see instead?

Concatenated JSON documents:

{
  "Dir": "whatever"
}
{
  "Dir": "whatever/else"
}
@bradfitz bradfitz added this to the Go1.10 milestone Aug 2, 2017
@bradfitz
Copy link
Contributor

bradfitz commented Aug 2, 2017

We can document this for Go 1.10 but I don't think we should change it. That would unnecessarily break existing tools consuming this. For instance, encoding/json.Decoder will consume multiple concatenated JSON objects.

@dmitshur
Copy link
Contributor

dmitshur commented Aug 2, 2017

Another way of describing "multiple concatenated JSON documents" is a that it's a JSON stream of objects. They are easy to parse.

@stevekuznetsov
Copy link
Author

For instance, encoding/json.Decoder will consume multiple concatenated JSON objects.

I was not aware of this -- there isn't really an issue, then, if it's simple to decode into []type from a concatenated document.

@dmitshur
Copy link
Contributor

dmitshur commented Aug 2, 2017

@stevekuznetsov
Copy link
Author

Right on, using that encoding/json.Decoder.More() pattern now. Feel free to close this -- the issue here was really that I thought it was going to be super difficult to get an API into the really awesome output of go list -- while this is still the case (os.Exec + json.Decoder is not the best), it's not not totally impossible. I would love to see the functions that resolve packages recursively be exported from some other utility package, but I understand to some extent why the backing logic for go list is private.

@dominikh
Copy link
Member

dominikh commented Aug 2, 2017

@stevekuznetsov There is github.com/kisielk/gotool which contains an exported copy of the Go tool's resolution of package paths (... and so on)

@rsc rsc closed this as completed Nov 2, 2017
@golang golang locked and limited conversation to collaborators Nov 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants