Skip to content

Serve command fails when using go workspaces #8

@macabot

Description

@macabot

Related code

out, err := exec.Command("go", "list", "-json", "-m").Output()
cobra.CheckErr(err)
var mod moduleList
cobra.CheckErr(json.Unmarshal(out, &mod))

The go list -json -m command normally returns the following JSON inside the senet repo:

{
	"Path": "github.com/macabot/senet",
	"Main": true,
	"Dir": "/home/user/repos/github.com/macabot/senet",
	"GoMod": "/home/user/repos/github.com/macabot/senet/go.mod",
	"GoVersion": "1.23.0"
}

However, it returns multiple JSON objects when there is a go.work file in the macabot directory:

{
	"Path": "github.com/macabot/hypp",
	"Main": true,
	"Dir": "/home/user/repos/github.com/macabot/hypp",
	"GoMod": "/home/user/repos/github.com/macabot/hypp/go.mod",
	"GoVersion": "1.23.0"
}
{
	"Path": "github.com/macabot/senet",
	"Main": true,
	"Dir": "/home/user/repos/github.com/macabot/senet",
	"GoMod": "/home/user/repos/github.com/macabot/senet/go.mod",
	"GoVersion": "1.23.0"
}

This can't be parsed by json.Unmarshal, which gives the error:

invalid character '{' after top-level value

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions