2019-08-05 00:13:27 +03:00
|
|
|
package here
|
|
|
|
|
2019-09-12 04:29:39 +03:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
)
|
2019-08-05 00:13:27 +03:00
|
|
|
|
|
|
|
// Package attempts to gather info for the requested package.
|
|
|
|
//
|
|
|
|
// From the `go help list` docs:
|
|
|
|
// The -find flag causes list to identify the named packages but not
|
|
|
|
// resolve their dependencies: the Imports and Deps lists will be empty.
|
|
|
|
//
|
|
|
|
// A workaround for this issue is to use the `Dir` field in the
|
|
|
|
// returned `Info` value and pass it to the `Dir(string) (Info, error)`
|
|
|
|
// function to return the complete data.
|
|
|
|
func Package(p string) (Info, error) {
|
2019-09-12 04:29:39 +03:00
|
|
|
return Cache(p, func(p string) (Info, error) {
|
|
|
|
var i Info
|
|
|
|
b, err := run("go", "list", "-json", "-find", p)
|
|
|
|
if err != nil {
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
if err := json.Unmarshal(b, &i); err != nil {
|
|
|
|
return i, err
|
|
|
|
}
|
2019-08-05 00:13:27 +03:00
|
|
|
|
2019-09-12 04:29:39 +03:00
|
|
|
return i, nil
|
|
|
|
})
|
2019-08-05 00:13:27 +03:00
|
|
|
}
|