News for hackers. Stuff that matters.
Re:Go at Digital Ocean by weberc2 on Sunday November 05, 2017 @04:11PM (#15631586)
GOPATH isn't a real problem; it's just a search directory like PATH or PYTHONPATH or CLASSPATH or NODEPATH, and it has a default value that makes it painless. Vendoring can be truly painful, but `dep` aims to fix that. Imports are not git URLs or indeed any kind of URLs; they're just directory paths into your GOPATH which the `go get` program can use if the directory path resembles the URL of a git (or hg/bzr/svn) repo. Don't think of `go get` as a package manager; think of it as a convenience utility to play around with a package before locking down the version via vendoring. Go's package management has a lot to improve on, but many of the common complaints are misinformed.

> I'm happy that there seems to be some movement. But now we have godep, govendor, glide, dep. and every project uses one or the other. Are they all compatible? Or is it a minefield?

They're not all compatible, but it's not really a problem because (last I checked) the prevailing philosophy was "libraries should not vendor--only binaries" which is to say "libraries shouldn't specify versions for their dependencies; the downstream binary projects should figure out what versions of each library should be used to build the binary". This means dependency tool compatibility isn't a problem because the dependency tooling punts on the dependency-resolution problem altogether, which seems like an even bigger problem.

Remember that this is only painful if you're trying for deterministic builds, and in the absolute worst case, you forego Go's build tooling and use something like Nix. This is absolutely not a reason to change language.

Re:Go at Digital Ocean by closeparen on Sunday November 05, 2017 @04:28PM (#15631714)
The existence of the GOPATH environment variable is not a problem. The fact that the toolchain is violently opinionated about where you locate your working copies, and goes out of its way to fight you if you try to fake it with symlinks, is.

The GOPATH issue will be solved when I can clone a project to anywhere in $HOME and build it without issue.

Re:Go at Digital Ocean by imsofuture on Sunday November 05, 2017 @04:35PM (#15631753)
This is how I felt when I started using go, but I was unable to rationalize why beyond 'it's different'.

What's the real difference between `cd ~/dev` and `cd $MYGO` (~/dev/go/src/github.com/myusername)?

Re:Go at Digital Ocean by KallDrexx on Sunday November 05, 2017 @05:58PM (#15632265)
The difference is the Go tooling is dictating your whole code layout that may not match your personal preference. I work in a multitude of languages and I organize my code in ~/code/work for work/contracting code bases, ~/code/personal for my code bases and ~/code/third-party for source code I want to look at and maybe contribute casually to. I have never figured out a good way to fit GOPATH into this without completely rearranging how I organize my code, which I have zero desire to do for one language, especially one that's not my main.
Re:Go at Digital Ocean by zaarn on Monday November 06, 2017 @09:16AM (#15635548)
You can specify multiple GOPATHs which will be searched in order for packages;

Your GOPATH could be set to "~/libs/go:~/code/work for work/contracting/go:~code/personal:~/code/third-party"

which would put any go-get libaries into ~/libs/go and allow using packages from the other folders. Keep in mind that Go will still use these Gopaths like any other Gopath repository; create a src/pkg/bin folder set for use with the compiler

Re:Go at Digital Ocean by KallDrexx on Monday November 06, 2017 @09:43AM (#15635759)
That's good to know, I had never come across that! Thanks.
Re:Go at Digital Ocean by golangnews on Sunday November 05, 2017 @05:27PM (#15632091)
Well imagine you use language foo, bar and go. Go insists all code lives in ~/go/src and foo insists it all lives in ~/foo/source. Neither likes symlinks, which one wins?

Also people like to keep other artefacts alongside source code like scripts, resources, templates, tools etc and often have an existing elaborate project structure in order to accommodate that. Go forces them to throw that out and use something under gopath. It's annoying and an unnecessary stumbling block for people starting out in Go.

Re:Go at Digital Ocean by slrz on Sunday November 05, 2017 @08:20PM (#15632889)
Go doesn't insist that your code lives in ~/go/src. It can live anywhere beneath a directory of your choice. Note that there's no requirement that GOPATH contains only Go source code. You can put your scripts and resources, as well as other source code, right next to the Go sources.

So you just put your code into ~/src/project/a.go and ~/src/project/b.foo (assuming a GOPATH=$HOME).

Re:Go at Digital Ocean by golangnews on Monday November 06, 2017 @03:26AM (#15634067)
Note src vs source in the original comment. Go forces you to change everything else to conform to gopath. I use go a lot and am used to it now but IMO that is a Bad Thing.
Re:Go at Digital Ocean by weberc2 on Monday November 06, 2017 @07:56AM (#15635095)
Put Go stuff in $GOPATH/src and Foo stuff in ~/foo/source. Problem solved. Go doesn't dictate where non-Go code lives...

This is the least of all problems.

Re:Go at Digital Ocean by golangnews on Monday November 06, 2017 @08:24AM (#15635221)
So now your go stuff and foo stuff lives in different dirs based on which programming language it happens to use, not which project it is for. To you perhaps this is a non-problem, to others it appears to be and it is a recurring cause of grief for newcomers to go.
Re:Go at Digital Ocean by zaarn on Monday November 06, 2017 @09:17AM (#15635558)

    export GOPATH="~/go:~/foo"
GOPATH will use ~/go as default for go get and importing and fall back to any further folders specified.
Re:Go at Digital Ocean by alphaalpha101 on Sunday November 05, 2017 @05:17PM (#15632026)
The difference is that I don't want all my Go programs in a different place. I have my place where I put projects. I have ~/projects, ~/oldprojects, ~/defunctprojects. I have ~/contribprojects for things that aren't mine. I decide where my files go.