myitcv.io/go
is a wrapper around the go
tool that automatically sets the GOPATH
env variable based on the process'
current directory (which we refer to as $PWD
for brevity). See the Goal section below for motivation.
The GOPATH
passed to the go
tool is calculated as follows:
- The existence of a
._gopath
file in a directoryd1
setsGOPATH
tod1
; this is evaluated for each directoryd1
on the path from$PWD
towards/
. If no suchd1
exists, setGOPATH
to themyitcv.io/go
process' environment variableGOPATH
(if set), else$HOME/go
- The existence of a
_vendor
directory in a directoryd2
causesd2/_vendor
to be prepended toGOPATH
. This is evaluated for each directoryd2
on the path fromd1
(or/
ifd1
did not exist) towards$PWD
.
The algorithm is relatively simple; myitcv.io/go/updateenv
's init
should be relatively understandable therefore.
myitcv.io/go
is designed to be used in place of the go
tool. Indeed it is implemented under the assumption that
myitcv.io/go
resolves before the go
tool in your PATH
.
Therefore, assuming the go
tool is already on your PATH
, do something equivalent to the following
go get -u myitcv.io/go
mkdir -p "$HOME/bin/myitcv_io_go"
go build -o "$HOME/bin/myitcv_io_go/go" myitcv.io/go
and then ensure $HOME/bin/myitcv_io_go
is at the beginning of your PATH
:
# in .bashrc or equivalent
export PATH="$HOME/bin/myitcv_io_go:$PATH"
# ...
The goal behind this tool is to explore how a true auto-GOPATH implementation might work within Go proper. But there is
an obvious flaw to the approach of "wrapping" the go
tool: any program other than the go
tool that depends on a
package that itself uses the value of GOPATH
will no longer function correctly. Hence myitcv.io/go
imports
myitcv.io/go/updateenv
for its side effect where the process' GOPATH
environment variable is updated. Other programs
should import this package for its side effects and be recompiled to experiment with this change in behaviour.