Overview
Set up a Go development environment.
Setting Up Go Environment
Install Go
Installation methods are omitted here. I use a tool called anyenv for installation.
Specify GOPATH
Add GOPATH to .bashrc or .bash_profile.
Check Go Directory Structure
The local environment directory structure will follow the official documentation.
Prepare a Go development directory named go_dev, and within it, create three directories based on their roles as specified in the official documentation. bin contains executable commands, pkg contains packages, and src contains source code. Only src/ is managed with git.
Create a Package
To verify that the setup is working correctly, create a package.
Inside src/, create a directory named test/ and a file main.go with the following content:
Run go build main.go to compile and create a binary file. Then, use go install to generate a binary file named test in bin/. If successful, the setup is complete.