Skip to content

pre-modules go get replacement needed, as it won't work outside of existsing module with modules enabled #27380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sirkon opened this issue Aug 30, 2018 · 6 comments

Comments

@sirkon
Copy link

sirkon commented Aug 30, 2018

So, I am currently using official build (that tgz file) for Linux with export GO111MODULE=on. And I am having troubles building binaries in a old way outside of any existing module:

$ go get golang.org/x/tools/cmd/goimports
go: cannot find main module; see 'go help modules'

As you see, I am trying to download and build goimports and then put the binary into $GOPATH/bin with this go get call. Thus, we are having obvious usability downgrade. Everything is OK when I do this inside some existing module, BTW.

I believe there should be some kind of replacement. It is clear go get is not the best place for this sort of functionality after go modules enabled. I guess there should be a new command specially for this case.

@jonstaryuk
Copy link

There are some workarounds in the wiki FAQ and discussion in #25922.

That said, this was a frustrating part of upgrading to Go 1.11 and the current "best practices" aren't ideal, imo.

@agnivade
Copy link
Contributor

Simply upgrading to 1.11 does not cause this issue. Explicitly setting GO111MODULE=on does. So that means you are explicitly telling the go command to work in module mode.

In any case, this is a duplicate of #24250.

@carlca
Copy link

carlca commented Sep 2, 2018

I have come up with what is a partial solution. It is a shell script which simulates the go get action. The idea is that one copies the git clone url from github.com and then runs gog.sh [⌘]v. Of course, with Github.com you can copy the git clone url with just a couple of keystrokes. One can then run go run, go build or go install as usual.

The contents of gog.sh can be found at https://gist.github.com/carlca/e97eccd545f2465f1e2a0c42356e6ffd.

I use an alias to save me even more keystrokes, alias gog='gog.sh'!

@sirkon
Copy link
Author

sirkon commented Sep 2, 2018

Translation into git clone is a bit too sophisticated IMO, I would rather go with something like

tmpDir=`mktemp`
cd $tmpDir
go mod init tmp/for/tool
go get $1

It creates temporary directory, cd into it, initializes a module within, perform go get which downloads, compiles and installs that damn binary :)

@ctd1500
Copy link

ctd1500 commented Sep 2, 2018

The "workaround" is very simple: set GO111MODULE=auto, or simply leave GO111MODULE unset and go get works just as it always has.

@sirkon
Copy link
Author

sirkon commented Sep 2, 2018

GO111MODULE=off go get …

is harder than

<exec name> …

@golang golang locked and limited conversation to collaborators Sep 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants