At Florida DrupalCamp, I got to talk to the DRUD team. They were demoing their DDEV tool, which is an open source local development stack. For a while I have been using my own platform-docker tool, which is a PHP based tooling command I used for scaffolding Docker, running Behat, and more. Instead of maintaining my already unmaintained tool, I decided to give DDEV a try and contribute back some things which I considered experience fixes.
DDEV is written in Golang. You can read more about its features and how to use it, I recommend hitting the documentation pages. I have messed with Golang a little. It is pretty fun and I have been wanting a reason to fiddle around with it. There is just one major GOWTF: working with third-party libraries and the GOPATH.
The GOPATH is where dependencies are downloaded and accessible. The default GOPATH is your in your home directory. As a Goland novice, I feel dependency management and locations are pretty confusing. The language feels great, but then there is this hindrance.
I decided to get GoLand by JetBrains installed and get a whirl at hacking on DDEV. A reason to use an IDE, over something like Visual Code Studio, is for all the fancy type hints and shortcuts to declarations.
New to Golang I decided to use the typical "import from Git" screen which put my project in ~/GolandProjects. But when I set up the project in GoLand I hit this.
So then I was like "oh, okay. I just need to fix my GOPATH!" I tried everything, and I couldn't get it to work. I tried setting my Project's GOPATH to everything I could think of, and nothing would work. I found a reported bug for the Goland IDEA plugin where vendor directory contents only worked if there was a src subdirectory. So I ran a script mentioned in the issues which makes a symlink of the vendor contents to vendor/src. I then configured GoLand to use the project's vendor directory as a local GOPATH.
This was all fine until it needed to import packages provided by the repository itself. At this point, I was in a very "face meet desk, repeat" mood. I hopped on Drupal Slack and luckily Randy Fay was online to help me troubleshoot.
The packages ddevapp, output, and util are provided by the project itself. But, with Golang, the proper way to reference them is through the fully qualified dependency directory, or at least that is how I understand it. It seems like the GoLand IDE is not set up to handle this. It is above my head so I just followed what Randy suggested: Make life simple and install the DDEV source into my global GOPATH and hack on it from there.
Works. For. Me.
So I ran the following command
# Create directories mkdir -p ~/go/src/github.com/drud/ # Move into the drud directory cd ~/go/src/github.com/drud/ # Clone my fork git clone [email protected]:mglaman/ddev.git
I then opened the directory in GoLand.
And everything worked! That is because the project was now within my GOPATH which allowed it to reference its own packages and vendor packages within the project.
So, now I know: when working on a Golang project to just stick to the GOPATH and keep it simple.