Golo Roden
Golo Roden

Reputation: 150872

Go workspace vs custom folder structure

I'm currently learning Go, and I have learned that Go suggests (expects? enforces?) that you use a specific folder layout for your workspace:

- my-go-workspace
  - src
  - bin
  - pkg

I perfectly understand the reasoning for this, and I definitely see its advantages. So, basically, I think it's a good thing to have a structure like this.

The only thing I don't like about this, is that it is a completely different structure from my other projects. E.g., for my Node.js projects there is a folder such as this:

- projects
  - moduleA
  - moduleB
  - ...

Now if I want to keep Node.js modules and Go packages side-by-side, in a unified folder structure I either have to use Go's way for Node.js as well (which feels wrong), or vice-versa (which feels wrong either).

I guess it's probably a dumb idea, and I should simply stick with Go's suggestion and live with two different ways of organizing my code (hey, it's different languages, why should the folder layout be the same?), but somehow this does not feel clean to me.

I know that this a highly subjective and personal, but my question is, if there are any practices out there on how to solve this? Or should I just live with it?

Upvotes: 4

Views: 641

Answers (2)

thwd
thwd

Reputation: 24848

A more simple idea:

golos-projects
 L node-project-a
    L what
    L ever
    L yolo
 L node-project-b
    L we
    L love
    L npm
 L go-project-a
    L src
    L pkg
    L bin
 L go-project-b
    L src
    L pkg
    L bin

And just set your GOPATH to e.g. golos-projects/go-project-b and hack away. When you want to switch to another project just change your GOPATH to the new project's folder.

Upvotes: 4

VonC
VonC

Reputation: 1328122

You can have the structure you want, as long as $GOPATH references a workspace which follows the convention

my-go-workspace
  - src
  - bin
  - pkg

In your case, src/ could simply be a symlink to projects/ (located anywhere else), in which you would have Node and Go projects.

Upvotes: 3

Related Questions