Engineering

⌘K
  1. Home
  2. Docs
  3. Engineering
  4. Go Programming Language

Go Programming Language

How to Install Go on Ubuntu 20.04

Reference: https://linuxize.com/post/how-to-install-go-on-ubuntu-20-04/

Golang Tutorial Using Visual Studio Code

Reference: https://www.bogotobogo.com/GoLang/GoLang_Visual_Studio_Code.php

Create A Go Module

cd ~/project/go-course/hello
go mod init hello

Build Go Program/Module

Use “go build”. If it errors like below, it means you haven’t initialized your folder as a Go module.

ceefour@amanah:~/go/src/hello$ go build
go: go.mod file not found in current directory or any parent directory; see 'go help modules'

Run Go Program

From Terminal:

go run hello

From VS Code, choose Run > Run Without Debugging or press Ctrl+F5. Alternatively, right click file and choose Run Code, or Alt+Ctrl+N.

Debug Go Program

From VS Code, choose Run > Start Debugging or press F5.

Frameworks & Libraries

Web framework / REST API: Echo

Mocking framework: GoMock

Unit test: Unit tests in Go

MongodB: mongo-go-driver

Go Language Resources / Books

Using Go Modules

Reference:

List The Current Module and All Its Dependencies

Command: go list -m all

$ go list -m all
(CURRENT MODULE)
cloud.google.com/go v0.26.0
github.com/BurntSushi/toml v0.3.1
github.com/DataDog/datadog-go v4.4.0+incompatible
github.com/DataDog/gostackparse v0.5.0
github.com/DataDog/sketches-go v1.0.0
github.com/Microsoft/go-winio v0.5.0
...

Using Makefiles

Reference: Makefiles with Go | golangdocs.com

Golang projects often use Makefiles to perform build management tasks such as installing dependencies, building, testing, etc.

Typical Makefile tasks for Golang projects:

  1. make installdep: Install dependencies. This runs go get and go mod commands.
  2. <code>make cleandep: Add missing and remove unused modules, using go mod tidy.
  3. <code>make build-image: Build Docker container image.
  4. <code>make test: Run code coverage and unit tests using go test. Code coverage is typically powered by Sonar, specified in sonar-project.properties file.
  5. <code>make install: Download modules to local cache using go mod download. This is similar to make installdep, but does not make vendored copy of dependencies.
  6. <code>make build: Build the Go project, but does not create a Docker container image.

Tags , ,

How can we help?