pkger/here/pkg.go

41 lines
868 B
Go
Raw Normal View History

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-21 19:51:29 +03:00
i, err := Cache(p, func(p string) (Info, error) {
2019-09-12 04:29:39 +03:00
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-09-21 19:51:29 +03:00
if err != nil {
return i, err
}
Cache(i.Dir, func(p string) (Info, error) {
return i, nil
})
return i, nil
2019-08-05 00:13:27 +03:00
}