Search code examples
goworkspacemicroservices

Golang Workspaces In Practice


According to the Go documentation they would like you to have a workspace that you should put all their projects in.1 However, as far as I can tell, this all falls apart as soon as you want to make a project that does not use Go exclusively.

Take a project where it is made up of many micoservices for example. Lets say that it is structured like this:

app/
    authentication/ (Using rust)
    users/ (Using NodeJS)
    posts/ (Using Go)

Only one part of the app would be written in Go, and that part is nested in a subdirectory of the app. How would I apply the Go workspace philosophy to this situation?


  1. https://golang.org/doc/code.html#Workspaces

Solution

  • You can put app/ in $GOPATH/src. Then whenever you're ready to build, you specify the path of your source files, relative to where they are in GOPATH.

    For example:

    if your app source is in $GOPATH/src/app/ and your .go files are in $GOPATH/src/app/posts/ then you can build a source (lets say posts.go in app/posts/) with go build $GOPATH/src/app/posts/posts.go or better go build posts/posts.go with app/ as your current working directory.