Devpack for Go¶
This tutorial shows how to use devpack-for-go to install a set of Go development tools, configure command aliases, use the available tools, and integrate the tools with VS Code on Ubuntu. The devpack packages the tools in a single snap that works alongside the official Go snap.
For background on devpacks, see Devpacks. For instructions on manually installing the Go toolchain, see How to set up a development environment for Go on Ubuntu.
Installing the devpack¶
devpack-for-go is a companion snap for the official go snap. It packages commonly used Go development tools while using the Go toolchain from the Go snap. Install both snaps with:
dev@ubuntu:~$ dev@ubuntu:~$ The devpack includes the following tools:
Delve – a debugger for Go programs
gopls– the official Go language servergolangci-lint– a fast lintergovulncheck– a vulnerability checkergotests– a test generatorgofumpt– a stricter formatter
Running the setup guide¶
The setup-guide command prints instructions for configuring command aliases and VS Code. Run it with:
dev@ubuntu:~$ The guide covers two tasks.
Enabling command aliases¶
Without aliases, each tool is available under its snap-qualified name, such as devpack-for-go.gopls. To run the tools directly, create aliases with snap alias:
dev@ubuntu:~$ Configuring VS Code¶
To integrate the tools into VS Code, add the following block to your settings.json file, usually at ~/.config/Code/User/settings.json:
~/.config/Code/User/settings.json¶{
"go.alternateTools": {
"dlv": "/snap/bin/devpack-for-go.delve",
"gopls": "/snap/bin/devpack-for-go.gopls",
"golangci-lint": "/snap/bin/devpack-for-go.golangci-lint",
"govulncheck": "/snap/bin/devpack-for-go.govulncheck",
"gotests": "/snap/bin/devpack-for-go.gotests",
"gofumpt": "/snap/bin/devpack-for-go.gofumpt"
},
"go.useLanguageServer": true,
"go.lintTool": "golangci-lint",
"go.formatTool": "gofumpt"
}
After updating the settings, restart VS Code or run Developer: Reload Window.
Using the tools¶
The tools installed by the devpack work on any Go project. To try them, create a small project:
dev@ubuntu:~$ dev@ubuntu:~/heygo$ Create a source file with a deliberate formatting issue:
heygo.go¶package main
import "fmt"
func greeting() string {
return "Hey Go!"
}
func main() {
fmt.Println(greeting())
}
Formatting with gofumpt¶
gofumpt is a stricter formatter than the standard gofmt. To reformat the file in place, run:
dev@ubuntu:~/heygo$ The indentation of the return and fmt.Println statements is corrected.
Linting with golangci-lint¶
To lint the project, run:
dev@ubuntu:~/heygo$ Checking for vulnerabilities with govulncheck¶
To scan the project for known vulnerabilities, run:
dev@ubuntu:~/heygo$ Generating tests with gotests¶
To generate a test stub for the greeting function, run:
dev@ubuntu:~/heygo$ This creates a heygo_test.go file with a generated test.
For a full guide to building, running, and debugging Go programs, including the Delve debugger, see Develop with Go on Ubuntu.