From bd04ceccc361ba3165b85692fd1fb3f7af74c7da Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Sat, 30 Nov 2019 16:37:55 -0500 Subject: [PATCH 1/2] add there package --- go.mod | 2 +- go.sum | 4 ++-- there/there.go | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 there/there.go diff --git a/go.mod b/go.mod index 69455b0..ebbb1db 100644 --- a/go.mod +++ b/go.mod @@ -7,5 +7,5 @@ require ( github.com/kr/pretty v0.1.0 // indirect github.com/stretchr/testify v1.4.0 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect - gopkg.in/yaml.v2 v2.2.5 // indirect + gopkg.in/yaml.v2 v2.2.7 // indirect ) diff --git a/go.sum b/go.sum index b7ab502..31792cc 100644 --- a/go.sum +++ b/go.sum @@ -18,5 +18,5 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c= -gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo= +gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/there/there.go b/there/there.go new file mode 100644 index 0000000..5673faf --- /dev/null +++ b/there/there.go @@ -0,0 +1,17 @@ +package there + +import "github.com/gobuffalo/here" + +var cache = here.New() + +func Dir(p string) (here.Info, error) { + return cache.Dir(p) +} + +func Package(p string) (here.Info, error) { + return cache.Package(p) +} + +func Current() (here.Info, error) { + return cache.Current() +} From fa086b0feda7436f405dd81568c92ba74b13a6e2 Mon Sep 17 00:00:00 2001 From: Mark Bates Date: Sat, 30 Nov 2019 16:47:09 -0500 Subject: [PATCH 2/2] added some docs --- current.go | 1 + here.go | 3 +++ there/there.go | 14 ++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/current.go b/current.go index 927633c..fb5b3e8 100644 --- a/current.go +++ b/current.go @@ -25,6 +25,7 @@ func (h Here) Current() (Info, error) { return h.current, h.curErr } +// Current returns the Info representing the current Go module func Current() (Info, error) { return New().Current() } diff --git a/here.go b/here.go index 3b6fb5b..cec1d76 100644 --- a/here.go +++ b/here.go @@ -15,6 +15,9 @@ type Here struct { current Info } +// New returns a Here type that will cache +// all results. This speeds up repeated calls, +// and can be useful for testing. func New() Here { return Here{ infos: &infoMap{ diff --git a/there/there.go b/there/there.go index 5673faf..51e333b 100644 --- a/there/there.go +++ b/there/there.go @@ -4,14 +4,28 @@ import "github.com/gobuffalo/here" var cache = here.New() +// Dir attempts to gather info for the requested directory. +// Results are cached globally inside the package. func Dir(p string) (here.Info, error) { return cache.Dir(p) } +// 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. +// Results are cached globally inside the package. func Package(p string) (here.Info, error) { return cache.Package(p) } +// Results are cached globally inside the package. +// Current returns the Info representing the current Go module func Current() (here.Info, error) { return cache.Current() }