News for hackers. Stuff that matters.
Re:Go 1.8 Release Candidate 1 is released by nishs on Tuesday January 10, 2017 @04:21PM (#13369124)
> The GOPATH environment variable now has a default value if it is unset. It defaults to $HOME/go on Unix and %USERPROFILE%/go on Windows. [0]

Finally. This is going to make it easier for newcomers to the Go ecosystem, since commands such as "go get" will now work out of the box.

[0] https://beta.golang.org/doc/go1.8#gopath

Re:Go 1.8 Release Candidate 1 is released by echelon on Tuesday January 10, 2017 @06:14PM (#13370166)
Why does Go require a special path for projects to be on? Python doesn't. Rust doesn't. This just seems annoying for no particular reason.
Re:Go 1.8 Release Candidate 1 is released by schmichael on Tuesday January 10, 2017 @06:26PM (#13370261)
Python has a list of locations to look for projects (modules) in (sys.path) and by default includes the working directory as the first item in that list.

Go has a list of locations to look for projects (packages) in ($GOPATH) and by default does not include the working directory. Unlike Python's sys.path, $GOPATH normally only contains a single value.

Python's behavior is similar to $PATH on Windows while Go's behavior is similar to $PATH on Unix.

There are pros and cons to each default value but either language can be overridden to have the other's behavior if you desire.

I personally quite like having a single unified $GOPATH for all of my source.

Re:Go 1.8 Release Candidate 1 is released by Manishearth on Tuesday January 10, 2017 @07:41PM (#13370746)
> There are pros and cons to each default value but either language can be overridden to have the other's behavior if you desire.

How? With Python I can release a package with code like `import foo from .` in it. This will not work in Go, a GOPATH package must import things from subdirectories via GOPATH. At least, this was the case the last time I checked.

Re:Go 1.8 Release Candidate 1 is released by thegeekpirate on Tuesday January 10, 2017 @08:31PM (#13371015)
Re:Go 1.8 Release Candidate 1 is released by shadowmint on Tuesday January 10, 2017 @09:05PM (#13371168)
Vendoring only works inside a GOPATH; if you're outside the GOPATH, the vendor/ folder is ignored.

https://github.com/golang/go/issues/14566

    There are many problems with running outside GOPATH. Among others, there's no
    caching of built object files, so everything is much slower than it should be
    (go build, go test, and so on). Vendoring is pretty low on the list of problems.

    It may be that GOPATH should be reconsidered but if so it should be done as a
    whole change, not just one piece at a time, like @bradfitz said above. 

    The solution for now is to use GOPATH.

    >  rsc closed this on 6 Dec 2016
Once the new dependency tool is done, it seems like GOPATH will be increasingly irrelevant with vendored dependencies and proper tooling.

(You may also be interested in this extended and active discussion on getting rid of GOPATH; https://github.com/golang/go/issues/17271)

Re:Go 1.8 Release Candidate 1 is released by thegeekpirate on Tuesday January 10, 2017 @09:14PM (#13371213)
You're absolutely correct—I just tested it, and I'll be damned. That's what I get for never playing around with it, and had (wrongly) assumed that this would have been one of the most basic features of vendoring.

I appreciate the correction!

Re:Go 1.8 Release Candidate 1 is released by Manishearth on Tuesday January 10, 2017 @09:33PM (#13371282)
Yeah, vendoring doesn't fix this problem as the sibling comment says. To be clear, I'm aware the team is aware of the inadequacies of the current system and is working on fixing it -- just saying that this doesn't work well now :)
Re:Go 1.8 Release Candidate 1 is released by thegeekpirate on Tuesday January 10, 2017 @10:07PM (#13371428)
Yep no worries—I was wondering why you wouldn't have known such a "basic" thing, and now I'm more knowledgeable because of it =)
Re:Go 1.8 Release Candidate 1 is released by schmichael on Thursday January 12, 2017 @06:28PM (#13387108)
True, you must put your source within a directory named src.
Re:Go 1.8 Release Candidate 1 is released by rat87 on Wednesday January 11, 2017 @12:11PM (#13375485)
I think sys.path defaults to PYTHONPATH (+interpreter relative lib path) if it exists
Re:Go 1.8 Release Candidate 1 is released by majewsky on Tuesday January 10, 2017 @06:25PM (#13370251)
Indeed. I have a couple of Go projects that are released in the classical manner as tarballs, which users can extract anywhere and compile with `make && make install`.

This used to work okay-ish until Go 1.5. Then Go 1.6 introduced vendoring support (i.e. you put the code for the libraries you need into your own repo) which is very nice if it works, so I wanted to have it. But `go build` stubbornly refuses to look at vendored code when you are not in the exact correct location inside the GOPATH.

To preserve the familiar build semantics, I set up the GOPATH inside the repo. Roughly like this:

  $ git clone https://github.com/foo/bar && cd bar
  $ mkdir -p .gopath/src/github.com/foo
  $ ln -sTf ../../../.. .gopath/src/github.com/foo/bar
  $ GOPATH=$PWD/.gopath go build github.com/foo/bar
Of course, all that bullshit can be nicely tugged away in the Makefile. For example: https://github.com/sapcc/swift-drive-autopilot/blob/a3d5d02b...

You can find this either hilarious or sad. I like the irony in using make(1) to patch up the deficiencies of a tool that was created decades after it.

Re:Go 1.8 Release Candidate 1 is released by i4k on Tuesday January 10, 2017 @08:43PM (#13371065)
> To preserve the familiar build semantics

You are trying to build Go in a way it wasn't designed for.

Go encourages absolute import paths (relative to $GOPATH) and solves a myriad of other language faults in this way. A good benefit is go-gettable projects, where all dependencies can be reached without a setup/configuration file (like setup.py, requirements.txt, and so on).

If you do not try to use Go like other language, your build should be something like:

  $ GOPATH=$PWD/some/path go get github.com/foo/bar
Re:Go 1.8 Release Candidate 1 is released by codemac on Wednesday January 11, 2017 @02:00AM (#13372288)
> You are trying to build Go in a way it wasn't designed for.

Yeah, I think his issue is with Go's choice to not search the current directory.

The go tools should let you use the current directory, and the "best practice" would have been vendoring to start, relative to the current directory. Then suddenly you see no GOPATH would be necessary at all! For example:

    % mkdir $proj
    % go get github.com/$dep1
    % go get github.com/$dep2
    % vim main.go
    % find .
    ./main.go
    ./github.com
    ./github.com/$dep1
    ./github.com/$dep1/somepkg
    ./github.com/$dep2
    ...
See, then main can import github.com/$dep1/somepkg, and it would be properly versioned and vendored! It falls out in a bunch of other ways of being nicer too IMO.

The currently GOPATH design encourages untracked and complected dependencies, where we're at 1.8 of the toolchain and we're still changing packaging behavior of dependencies.

Re:Go 1.8 Release Candidate 1 is released by majewsky on Wednesday January 11, 2017 @04:12AM (#13372727)
Note that my project is still go-gettable. I've structured it in such a way that it is familiar both to Go devs using `go get` and to users who know `tar xf && make && make install `.
Re:Go 1.8 Release Candidate 1 is released by ernsheong on Tuesday January 10, 2017 @07:05PM (#13370544)
There is a tool called gb that helps you with this

https://getgb.io/

(I have no affiliation with gb)

Re:Go 1.8 Release Candidate 1 is released by majewsky on Tuesday January 10, 2017 @08:27PM (#13370998)
While we're shamelessly plugging: I actually wrote my own vendoring tool after being confused by the ecosystem. It's a shell script of maybe 30 LOC: https://github.com/holocm/golangvend/blob/master/golangvend

I hope to abandon it for an official solution, though, given that it appears and is good.

Re:Go 1.8 Release Candidate 1 is released by tumdum_ on Wednesday January 11, 2017 @07:42AM (#13373523)
Go the language does not require any environment variable (see https://golang.org/ref/spec). Go the tool (that wraps compilations and linking) did depend on $GOPATH environment variable to find location of installed packages (see https://golang.org/cmd/go/#hdr-GOPATH_environment_variable).

In some ways this is similar to cargo which depends on existence of ~/.cargo

btw. you can manually invoke Go compiler and linker. A very simple example from some time ago can be found here: https://github.com/tumdum/go_build

Re:Go 1.8 Release Candidate 1 is released by boomlinde on Tuesday January 10, 2017 @06:55PM (#13370487)
It doesn't. Package imports are either relative to GOPATH, GOROOT, the vendor directory or to the current package path (e.g. `import "../sibling"`).

This doesn't restrict you to using a special path or a particular mode of organizing. Rather, it leaves much of that problem to the user, for better or for worse. It's perfectly fine to write programs with GOPATH unset.

Re:Go 1.8 Release Candidate 1 is released by dx034 on Wednesday January 11, 2017 @06:10AM (#13373144)
I actually really like that about Go. Not the fact that it wasn't set on standard, that was annoying. But the fact that Python modules can be anywhere as long as they're in some path can be confusing and hard to track down code. The Go mode is very restricting, but it keeps the environment tidy.
Re:Go 1.8 Release Candidate 1 is released by mrweasel on Wednesday January 11, 2017 @04:52AM (#13372861)
Honestly Python does too as soon you start working on multiple project or something larger. Sure virtualenv in Python allows you to specify where you want the project to be, but so does Go, just redefine GOPATH.
Re:Go 1.8 Release Candidate 1 is released by Walkman on Wednesday January 11, 2017 @04:04PM (#13377466)
Python has PYTHONPATH. I believe it's the exact same thing? The difference is that Python puts the current directory and the standard library in by default.
Re:Go 1.8 Release Candidate 1 is released by k2xl on Tuesday January 10, 2017 @04:29PM (#13369222)
Everyone I know who has learned Go has encountered this issue. "What's this GOPATH env variable? What should it be set to?" When I personally learned Go this (and how go do/doesn't do vendoring) was the hardest thing to learn. It's strange that it took this long to get this feature out.

Now if they could figure out a way to get go get to work nicely with private repos out of the box without SSH config hacks that'd be great..

Re:Go 1.8 Release Candidate 1 is released by ashark on Tuesday January 10, 2017 @05:08PM (#13369613)
I like Go, but the GOPATH thing gave a very bad first impression.
Re:Go 1.8 Release Candidate 1 is released by sofaofthedamned on Tuesday January 10, 2017 @04:25PM (#13369169)
Biggest thing on this release to be fair. Unbelievably simply but so effective, about time.
Re:Go 1.8 Release Candidate 1 is released by voidlogic on Wednesday January 11, 2017 @12:00AM (#13371873)
What about the 5-10% performance boost? For me thats like getting a few hundred thousand dollars worth of free hardware...
Re:Go 1.8 Release Candidate 1 is released by tedunangst on Tuesday January 10, 2017 @05:17PM (#13369705)
Curious why they didn't pick something like .go to be more out of the way.
Re:Go 1.8 Release Candidate 1 is released by stouset on Tuesday January 10, 2017 @05:20PM (#13369737)
Because it's supposed to be your actual development workspace. To be honest, I think this is one of the most asinine parts of the go development workflow (and there are a lot of contenders…). Having to organize all your go projects separately from everything else just because they happen to be developed in that particular language is maddening.
Re:Go 1.8 Release Candidate 1 is released by Manishearth on Tuesday January 10, 2017 @05:27PM (#13369784)
Yeah, this gets super annoying when you need your project written in other languages to contain go code.

I worked on the YCM support for godef, we eventually had to fork the library and rewrite paths since there was no way of pinning to a version within YCM. Libraries written with github paths for `go get` do not play nice with living outside of gopath, and libraries written with relative paths don't work with go get (even though this is something that go could support)

Re:Go 1.8 Release Candidate 1 is released by alexbecker on Tuesday January 10, 2017 @06:09PM (#13370124)
I use a make rule which appends the local go directories to GOPATH before running "go _". Inelegant, but it works.
Re:Go 1.8 Release Candidate 1 is released by jerf on Tuesday January 10, 2017 @10:31PM (#13371523)
I've got a couple of projects that contain Go code. The Go code does not need to be the top level of the project. I just either check it out into the gopath or symlink it in (usually the former since I've already set up CDPATH in bash to go to the directory the project is living in), and the import paths in my go code point at something like scm.localdomain.com/team/project/go, where the "project" directory is the top level directory for the project that has no Go code in it. This is even fully go getable if you "go get scm.localdomain.com/team/project/go/cmd/whatever" or something.
Re:Go 1.8 Release Candidate 1 is released by Manishearth on Tuesday January 10, 2017 @10:36PM (#13371550)
YCM can't require its users to do that, nor can it pollute the gopath which may not be set when it is installed, nor can it rely on that path always being the same or the installed files not being removed.

It's fine for a Go project, but this is not a Go project. It should not be forced to change how it works because it wants to contain some Go code.

Re:Go 1.8 Release Candidate 1 is released by mixedCase on Wednesday January 11, 2017 @12:03AM (#13371885)
>It should not be forced to change how it works because it wants to contain some Go code.

Go is not like Python, the end result is a binary, not interpreted source code. You can simply write a build script that sets a custom GOPATH inside a temporary folder, pulls all dependencies, builds and pops out a binary ready for use; and you can either discard or save your custom GOPATH anywhere for caching purposes.

Re:Go 1.8 Release Candidate 1 is released by Manishearth on Wednesday January 11, 2017 @12:08AM (#13371905)
Fair.

Note that this wasn't the only reason we had to fork. Go doesn't (or didn't) provide a way to pin to a dependency, so we would have had to fork anyway, and then rewrite all the paths anyway, so I went the way of using local paths in the fork.

Re:Go 1.8 Release Candidate 1 is released by mixedCase on Wednesday January 11, 2017 @01:09PM (#13376005)
You can probably consider unforking now that the vendor directory is a thing. I'm sure it'd be easier than rebasing on every update.
Re:Go 1.8 Release Candidate 1 is released by geoka9 on Tuesday January 10, 2017 @05:35PM (#13369852)
I actually like it. Makes it really easy to share code between my own programs - really handy for "microservice" projects. And if I want to have a Go program in a different source tree, links allow me to do that.
Re:Go 1.8 Release Candidate 1 is released by takeda on Tuesday January 10, 2017 @06:25PM (#13370256)
Go is opinionated how things are done, and just happens that its opinion fits yours, the issue is what when it doesn't?

With non-opinionated languages nothing is stopping you from structuring your code the same way.

Some people stated how hard go makes it when you try to have project that utilizes different languages. Another issue is when you try to use a fork of one of library.

Yet another is that it is much more complex to generate a package (e.g. rpm) of projects that has many dependencies.

Re:Go 1.8 Release Candidate 1 is released by geoka9 on Tuesday January 10, 2017 @09:46PM (#13371342)
> With non-opinionated languages nothing is stopping you from structuring your code the same way.

With Go, I can do `go build $project` from anywhere and get a releasable binary in the working directory. I can do `import "$oldproject/$package"` in my new project and start using it immediately. I can use `godef` to jump around all of the Go code installed on my system and quickly drill down all the way to the Go builtins if I need to. I can use `guru` to see all references to a definition across all of the Go packages installed on my system. The list goes on. And I can do all of that from a favorite text editor (and not a huge slow IDE). I never felt so liberated in any other programming environment, and I've used quite a few.

> Yet another is that it is much more complex to generate a package (e.g. rpm) of projects that has many dependencies.

Go binaries have only the standard system libraries for dependencies - for all practical purposes they can be considered static. Or you mean something else?

> Some people stated how hard go makes it when you try to have project that utilizes different languages.

I've used links successfully, but maybe my scenarios were not complex enough?

> Another issue is when you try to use a fork of one of library.

Vendor support since 1.6 made this a nonissue; it's now trivial to use forked versions of libraries.

Re:Go 1.8 Release Candidate 1 is released by Merovius on Wednesday January 11, 2017 @12:09PM (#13375464)
> Another issue is when you try to use a fork of one of library.

A fork of a library is either identical to the original, or a new library. And you could argue (or rather: I do), that it is a good thing that you need to explicitly specify which one you intend to use.

Re:Go 1.8 Release Candidate 1 is released by takeda on Friday January 13, 2017 @01:09PM (#13393005)
So let say you use code with many dependencies, but you want to make a small change in one of the dependencies. In other languages you would then just compile and be done with it, but now with golang you now need to also modify potentially hundreds of places unless you resort to somehow cheat golang.

As I said, being opinionated is great if the opinion matches yours otherwise you might end up fighting it on every step.

Re:Go 1.8 Release Candidate 1 is released by alexbecker on Tuesday January 10, 2017 @06:12PM (#13370152)
But how do you distribute such a project? Do you need an install script with any OSS project that includes go code, which sets up a bunch of links in the user's GOPATH directory? I imagine this script would be bug-prone and difficult for most users to debug.
Re:Go 1.8 Release Candidate 1 is released by regecks on Tuesday January 10, 2017 @06:54PM (#13370483)
I distribute commercial Go source with a Dockerfile to build the app (and rpm package) and it has been received remarkably well - better than I had imagined. YMMV.
Re:Go 1.8 Release Candidate 1 is released by geoka9 on Tuesday January 10, 2017 @10:06PM (#13371421)
I've only used Go for SaaS backends but if I wanted to distribute the code to 3rd parties I'd probably use a Dockerfile too.
Re:Go 1.8 Release Candidate 1 is released by gluczywo on Tuesday January 10, 2017 @06:09PM (#13370122)
You can view GOPATH centered development as a sign of simplicity. Probably not the most elegant thing in the world but the code organization is easy to fix with:

ln -s PROJECT_SOURCE_FOLDER $GOPATH/src/

Re:Go 1.8 Release Candidate 1 is released by majewsky on Tuesday January 10, 2017 @06:31PM (#13370289)
I actually adopted the GOPATH structure for all my repos, with some shell-script tooling (e.g. `cg github.com/foo/bar` is equivalent to `cd $GOPATH/src/github.com/foo/bar`, but clones the repo on first use). While transitioning to it, I indeed found quite a few repos that were checked out multiple times below my $HOME because of inconsistent directory structures.
Re:Go 1.8 Release Candidate 1 is released by derimagia on Tuesday January 10, 2017 @07:18PM (#13370616)
I use https://github.com/motemen/ghq for that, which is really nice actually.
Re:Go 1.8 Release Candidate 1 is released by Merovius on Wednesday January 11, 2017 @11:58AM (#13375359)
FWIW: I instead started organizing my workspace in the GOPATH layout (that is, I have GOPATH=~ and put a C project cloned from github.com/foo/bar at ~/src/github.com/foo/bar too). It also helps knowing where $random_repo was cloned from. YMMV
Re:Go 1.8 Release Candidate 1 is released by acln on Tuesday January 10, 2017 @09:33PM (#13371281)
I use GOPATH=$HOME. All the code (Go and other languages) lives under $HOME/src.
Re:Go 1.8 Release Candidate 1 is released by bluejekyll on Tuesday January 10, 2017 @09:52PM (#13371364)
And what about .git? And roots compatible with what other Devs expect?
Re:Go 1.8 Release Candidate 1 is released by Merovius on Wednesday January 11, 2017 @12:12PM (#13375497)
I don't see any problems with .git. Most go packages use git anyway, it would be pretty amazing if go tooling would break if you have a .git directory anywhere.

Re the other question: If you don't run a go command with a path name, it doesn't matter what the directory structure is. I have tons of non-go projects in my GOPATH and build them with the usual tools. No issues.

Re:Go 1.8 Release Candidate 1 is released by nishs on Wednesday January 11, 2017 @03:32PM (#13377258)
Running

  GOPATH=$HOME go get github.com/foo/bar
would download the package to:

  $HOME/src/github.com/foo/bar
So $HOME will not have .git.
Re:Go 1.8 Release Candidate 1 is released by 4ad on Wednesday January 11, 2017 @06:41AM (#13373242)
What about git?
Re:Go 1.8 Release Candidate 1 is released by bluejekyll on Wednesday January 11, 2017 @10:34AM (#13374615)
I was curious about how this recommendation effects other Devs and the .git and other similar paths in the Dev workflow.

That is, is the root of each go project effected?

Re:Go 1.8 Release Candidate 1 is released by 4ad on Friday January 13, 2017 @06:17AM (#13389965)
Sorry, I don't understand the question.

I also set GOPATH=$HOME, and all my source code (not only Go) lives in $HOME/src, and I do use git for both Go and non-Go projects (so they have a .git directory in $HOME/src/what/ever/.git), and there's no problem. Why would there be one?

Re:Go 1.8 Release Candidate 1 is released by fixermark on Tuesday January 10, 2017 @05:24PM (#13369768)
Java seems to have gone that road. Not sure if it was a bad idea or not.
Re:Go 1.8 Release Candidate 1 is released by Psyonic on Tuesday January 10, 2017 @05:36PM (#13369855)
In what way did Java go that road? Java doesn't impose any constraint on location across projects.
Re:Go 1.8 Release Candidate 1 is released by StevePerkins on Tuesday January 10, 2017 @05:51PM (#13369975)
What are you talking about? It's simple to mix Java and C++ (or whatever) within the same project.

Wellllllllll... until you actually start to write code against JNI, of course. But the project LAYOUT is simple!

Re:Go 1.8 Release Candidate 1 is released by wtetzner on Tuesday January 10, 2017 @07:32PM (#13370706)
> Wellllllllll... until you actually start to write code against JNI, of course.

JNA[1] makes things much simpler.

[1] https://github.com/java-native-access/jna

Re:Go 1.8 Release Candidate 1 is released by vanderZwan on Tuesday January 10, 2017 @06:10PM (#13370135)
Rob Pike considers hidden/dot files to be a bad idea

https://plus.google.com/u/0/+RobPikeTheHuman/posts/R58WgWwN9...

Re:Go 1.8 Release Candidate 1 is released by utborin on Wednesday January 11, 2017 @12:11AM (#13371920)
"For those who object that dot files serve a purpose, I don't dispute that but counter that it's the files that serve the purpose, not the convention for their names."

Oh, that's rich. This from the guy who designed a language where the case of a symbol's name determines the symbol's visibility.

Re:Go 1.8 Release Candidate 1 is released by vanderZwan on Wednesday January 11, 2017 @05:23AM (#13372960)
That comparison makes little sense, given that these are the actual arguments he has against dot-files:

> First, a bad precedent was set. A lot of other lazy programmers introduced bugs by making the same simplification. Actual files beginning with periods are often skipped when they should be counted.

> Second, and much worse, the idea of a "hidden" or "dot" file was created. As a consequence, more lazy programmers started dropping files into everyone's home directory.

> I don't have all that much stuff installed on the machine I'm using to type this, but my home directory has about a hundred dot files and I don't even know what most of them are or whether they're still needed. Every file name evaluation that goes through my home directory is slowed down by this accumulated sludge.

At least, I can't think of any similar problems that semantically significant casing in Go creates.

Re:Go 1.8 Release Candidate 1 is released by krakensden on Tuesday January 10, 2017 @08:42PM (#13371061)
Arg, that's my GOROOT. For a while it was going to be ~/gocode, when did it get changed?
Re:Go 1.8 Release Candidate 1 is released by sagichmal on Wednesday January 11, 2017 @03:17AM (#13372521)
The default only applies if you don't have your own GOPATH explicitly set, so you'll be fine.
Re:Go 1.8 Release Candidate 1 is released by Merovius on Wednesday January 11, 2017 @12:16PM (#13375518)
…until, at some point, you run a go command from a different shell or something, where GOPATH isn't set for some reason ;)
Re:Go 1.8 Release Candidate 1 is released by gjvc on Wednesday January 11, 2017 @08:00AM (#13373605)
Think I would have preferred $HOME/lib/go/ on UNIX ...
Re:Go 1.8 Release Candidate 1 is released by fnord123 on Wednesday January 11, 2017 @08:26AM (#13373718)
XDG doesn't have a XDG_LIB_HOME but I would guess it should be $HOME/.local/lib
Re:Go 1.8 Release Candidate 1 is released by amckinlay on Tuesday January 10, 2017 @11:35PM (#13371782)
And why not ~/Library/ for Mac?