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