Skip to content

Commit

Permalink
Blog - Setting up a go development environment (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmartinez287 authored Mar 13, 2024
1 parent 7f9aac8 commit 98d4caa
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 1 deletion.
60 changes: 60 additions & 0 deletions public/img/blog/2024/03/Go-Logo_Aqua.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/content/blog/contributor-training.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Live training sessions will be held weekly on Tuesdays at 8am US MT, 5pm CET or
|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 2023-07-11 | [Testing DDEV Features, testing DDEV v1.22.0 prereleases, how to help](https://www.dropbox.com/scl/fi/8epf3vqrp6f5rf7w7up7l/20230711_contributor_training_testing_release.mp4?rlkey=s8zd82uc7a33kke9ksiqsi1yb&dl=0) |
| 2023-07-18 | [Maintaining and Improving the Docs](https://www.dropbox.com/scl/fi/2d5qryxzgwa5zat9xz056/20230718_contributor_traiing_docs.mp4?rlkey=senzp6l6j8zq52vd4y74uhqfy&dl=0) |
| 2023-07-25 | [Setting up a Go Development Environment](https://www.dropbox.com/scl/fi/gka3bwm3pwpchryg50l0t/20230725_contributor_training_go_environment.mp4?rlkey=3hlhugszdxi4hm6rmwlw28r5f&dl=0) |
| 2023-07-25 | [Setting up a Go Development Environment](https://youtu.be/IjrJw0Ay-dk) see [blog](/blog/setting-up-a-go-development-environment) |
| 2023-08-08 | [Running Automated Tests Locally](https://www.dropbox.com/scl/fi/952kiwyqb60613plctr7f/2023-08-08_contributor_training_running_tests.mp4?rlkey=14t3xj6es707osboxc6c4n6a1&dl=0) |
| 2023-08-15 | [Maintain and improve ddev.com](https://www.dropbox.com/scl/fi/up13ll31115zo997kqzac/2023-08-15_contributor_training_maintain_ddev.com.mp4?rlkey=uff5jra0dp524utuigv9j6399&dl=0) see [outline](https://doc.mattstein.com/s/-BQQaSLJd) and [blog post](https://ddev.com/blog/ddev-website-for-contributors/) |
| 2023-08-22 | [Supporting others: How can I help?](https://www.dropbox.com/scl/fi/iiu0ywf3h958wcqchykk4/2023-08-22_contributor_training_support.mp4?rlkey=ujqml1hfwbfyutwizy2jmlet9&dl=0) see [blog](https://ddev.com/blog/how-to-give-and-get-community-support/) |
Expand Down
92 changes: 92 additions & 0 deletions src/content/blog/setting-up-a-go-development-environment
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
title: "Setting up a Go Development Environment for DDEV"
pubDate: 2024-03-15
summary: "DDEV Contributor Live Training: Setting up a Go Development Environment."
author: Bernardo Martinez
featureImage:
src: /img/blog/2024/03/Go-Logo_Aqua.svg
alt: Golang Logo.
categories:
- Guides
- Community
---

The DDEV Community has regular contributor training sessions, and in July, 2023 we talked about setting up a Go (Golang) development environment for DDEV. This blog summarizes [the contributor training session](https://youtu.be/IjrJw0Ay-dk). The (Min digit) syntax added below provides the minute on which each subject is covered on the recording.

## Installing Go on different Operation Systems ([Min 10:51](https://youtu.be/IjrJw0Ay-dk?t=647))

Randy used macOS and recommended Homebrew as the tool to manage Go updates.

The first command recommended was

```
brew install go golangci-lint
```

DDEV uses [make](https://www.gnu.org/software/make/) ([Min 13:32](https://youtu.be/IjrJw0Ay-dk?t=810)) to build its binary. Make is included with the macOS Command-Line Tools for XCode and can be installed with `xcode-select --install`, but that is already required to install Homebrew, so should already be installed.

## Cloning [DDEV](https://github.com/ddev/ddev) repository ([Min 15:30](https://youtu.be/IjrJw0Ay-dk?t=932))

Check out the `ddev` repository with `git clone [email protected]:ddev/ddev -o upstream`. Run `make` to create a new binary. The DDEV Makefile will automatically detect your host OS and build the appropriate binary. However, one can provide a parameter to build others. As an example, `make darwin_amd64` builds the macOS AMD64 binary.

At ([Min 16:30](https://youtu.be/IjrJw0Ay-dk?t=982)) the Makefile located in the root of the DDEV project is lightly explained.

Randy usually symlinks the built binary version to a place inside the `$PATH`, but to run a newly compiled binary one can specify its fully qualified path. For example:

```
./.gotmp/bin/darwin_arm64/ddev --version
```

If we want to avoid prefixing ddev with its built path instructions are included at ([Min 17:37](https://youtu.be/IjrJw0Ay-dk?t=1056)). `ddev --version` describes which binary version is currently used; it's selected by your `$PATH`.

## The role of `mkdocs` ([Min 21:22)https://youtu.be/IjrJw0Ay-dk?t=1276))

`mkdocs` can be tested with `make makedocs`

Makedocs is used for previewing and contributing to the docs. It's named makedocs but it's not related to the make tool or compiling the binary.

You can preview a built version of the docs you're working with using `make mkdocs-serve`.

## Randy IDE of choice is Goland ([Min 23:50](https://youtu.be/IjrJw0Ay-dk?t=1547))

Goland is very similar to PHPStorm and of course is made by the same JetBrains company.

One fantastic thing about Go is that there is only one way to format it ([Min 26:10](https://youtu.be/IjrJw0Ay-dk?t=1576)). It always uses tabs and the same indentation. It all follows the standards set by `gofmt`.

## Debugging DDEV Go Code ([Min 28:17](https://youtu.be/IjrJw0Ay-dk?t=1699))

To verify formatting and static analysis use `make golangci-lint`

`golangci-lint` is the tool used on DDEV CI/CD for incoming pull requests.

For new feature-based pull requests ([Min 31:34](https://youtu.be/IjrJw0Ay-dk?t=1892)) Randy recommends starting with an issue to explain to maintainers the context surrounding their concerns before beginning a PR.

The [DDEV Docs development tab](https://ddev.readthedocs.io/en/latest/developers/) ([Min 32:20](https://youtu.be/IjrJw0Ay-dk?t=1938)) includes plenty of tips and insights.

#### [GOLand](https://www.jetbrains.com/go/) debugging insights ([Min 33:39](https://youtu.be/IjrJw0Ay-dk?t=2014))

At this point Randy showed us a demo on how to run `ddev/cmd/debug-config-yml.go` by first running main.go and then setting the working directory to match an active ddev project.

#### VSCode Go debugging ([Min 37:50](https://youtu.be/IjrJw0Ay-dk?t=2268))

The following extension is mentioned, [Go](https://marketplace.visualstudio.com/items?itemName=golang.Go) by the Go team at Google.

DDEV comes with a launch.json prebuilt for you. It includes the config that might be found in Goland UI but for VsCode. The one item Randy usually has to change is the working directory ([Min 39:57](https://youtu.be/IjrJw0Ay-dk?t=2395)). He then showed an example on how to debug Go in VSCode.

The most important GO files are in pkg/ddevapp ([Min 44:26](https://youtu.be/IjrJw0Ay-dk?t=2660)), the ones in cmd are the ones associated with a commands and the pkg Go files are functionality.

[Cobra](https://cobra.dev/) is the library used for command flags and arguments. A lot of the commands in the cmd directory are just an implementation that calls other things.

At ([Min 49:43](https://youtu.be/IjrJw0Ay-dk?t=2977)) a question arose from a user's ability to get VSCode Go working:

```
"cwd":"${workspaceRoot}/../d9simple"
```
The issue was that "d9simple" is a placeholder string that needs to point to a real DDEV directory.

At ([Min 50:50](https://youtu.be/IjrJw0Ay-dk?t=3048)) we can see a walkthrough of running Go tests in VSCode.

devcontainer.json ([Min 58:35](https://youtu.be/IjrJw0Ay-dk?t=3507)) is a file for Github Codespaces.

## Keep in touch!
Join us in [Discord](https://discord.gg/hCZFfAMc5k) or [open an issue](https://github.com/ddev/ddev/issues) or send [an email](mailto:support%40ddev.com) if you have success (or failure 😀).

0 comments on commit 98d4caa

Please sign in to comment.