Application 2018-04-07

Setting Up a Golang Development Environment

Configure a Go development environment: GOPATH setup, directory structure, package organization, and Docker development.

Read in: ja
Setting Up a Golang Development Environment

Overview

We will set up the Go environment.

Setting Up Go Environment

Installing Go

The installation method is omitted. I use a tool called anyenv for installation.

Specifying GOPATH

Specify GOPATH in .bashrc or .bash_profile.

export GOPATH=$HOME/localdev/project/go_dev // Set as you like
PATH=$PATH:$GOPATH/bin

Checking Go Directory Structure

The directory structure in the local environment will be organized according to the official documentation.

go_dev/
├── bin
├── pkg
└── src

A development directory for Go called go_dev is prepared, containing three directories for different roles, in accordance with the official documentation's directory structure. Executable commands are placed in bin, packages in pkg, and sources in src. The src/ directory is managed by git.

Creating a Package

As a check to see if the setup so far is successful, let's create a package.

Prepare a test/ directory in src/ and create a file called main.go as follows:

package main

import "fmt"

func main() {
	fmt.Println("Hello, 世界")
}

Compile with go build main.go, create a binary file, and if a binary file named test is generated in bin/ with go install, you're all set.

Setting Up a Docker Development Environment

Tags: Golang
Share: 𝕏 Post Facebook Hatena
✏️ View source / Discuss on GitHub
☕ Support

If you enjoy this blog, consider supporting it. Every bit helps keep it running!


Related Articles