You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: go-wrapper
+21-15Lines changed: 21 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -10,17 +10,19 @@ usage: $base command [args]
10
10
This script assumes that is is run from the root of your Go package (for
11
11
example, "/go/src/app" if your GOPATH is set to "/go").
12
12
13
-
The main feature of this wrapper over the native "go" tool is that it supports
14
-
the addition of a ".godir" file in your package directory which is a plain text
15
-
file that is the import path your application expects (ie, it would be something
16
-
like "github.com/jsmith/my-cool-app"). If this file is found, the current
17
-
package is then symlinked to /go/src/<.gopath> and the commands then use that
18
-
full import path to act on it. This allows for applications to be universally
19
-
cloned into a path like "/go/src/app" and then automatically built properly so
20
-
that inter-package imports use the existing source instead of downloading it a
21
-
second time. This also makes the final binary have the correct name (ie,
22
-
instead of being "/go/bin/app", it can be "/go/bin/my-cool-app"), which is why
23
-
the "run" command exists here.
13
+
In Go 1.4, a feature was introduced to supply the canonical "import path" for a
14
+
given package in a comment attached to a package statement
15
+
(https://golang.org/s/go14customimport).
16
+
17
+
This script allows us to take a generic directory of Go source files such as
18
+
"/go/src/app" and determine that the canonical "import path" of where that code
19
+
expects to live and reference itself is "github.com/jsmith/my-cool-app". It
20
+
will then ensure that "/go/src/github.com/jsmith/my-cool-app" is a symlink to
21
+
"/go/src/app", which allows us to build and run it under the proper package
22
+
name.
23
+
24
+
For compatibility with versions of Go older than 1.4, the "import path" may also
25
+
be placed in a file named ".godir".
24
26
25
27
Available Commands:
26
28
@@ -46,12 +48,14 @@ if ! shift; then
46
48
exit 1
47
49
fi
48
50
49
-
dir="$(pwd -P)"
50
-
goBin="$(basename "$dir")"# likely "app"
51
+
goDir="$(go list -e -f '{{.ImportComment}}'2>/dev/null || true)"
51
52
52
-
goDir=
53
-
if [ -f .godir ];then
53
+
if [ -z"$goDir"-a-s .godir ];then
54
54
goDir="$(cat .godir)"
55
+
fi
56
+
57
+
dir="$(pwd -P)"
58
+
if [ "$goDir" ];then
55
59
goPath="${GOPATH%%:*}"# this just grabs the first path listed in GOPATH, if there are multiple (which is the detection logic "go get" itself uses, too)
0 commit comments