This video tutorial describe how to setup Mac environment for GoLang! Instructions: 1. Download Go from - and Install 2. Installing Golang on Mac OS X Google provides the package file for OS X. All you have to do is visit this page and grab the latest version. Once downloaded, open it, and follow the prompts to install the Go tools.
Download the installer package for your OS version and architecture. Once downloaded go to your Downloads folder in Finder and double click on the pkg file to start the installation. The installation will put Go in /usr/local/go. Once the installation is complete you will want to check the installation. Download the latest Go package (.pkg) file from Go’s official downloads page. Open the package and follow the on-screen instructions to install Go. By default, Go will be installed in /usr/local/go. Use LiteIDE development golang need to install the Go language development environment. Download the archive and extract it into c. For Mac OS X, you don.
Running a load testing Go utility using Docker for Mac
I’m playing around with Zeit Now at the moment (see my previous entry) and decided to hit it with some traffic using Apache Bench. I got this SSL handshake error:
Some brief Googling turned up this thread on Stack Overflow, which suggested trying hey as an alternative. Hey is a load testing utility written in Go, and the installation instructions are as follows:
Unfortunately, I don’t have a current Go environment set up on this laptop—I have Go 1.6, but Hey calls for at least Go 1.7.
Rather than work through upgrading my Go environment, I decided to see if I could get this tool working using Docker for Mac.
We recently switched to Docker for Mac for running our development environments at work, and having worked through various iterations of Docker over the past few years Docker for Mac offers by far the most pleasant developer experience. You download the installer, run it, and now
docker info
in a terminal will reveal a fully functioning Docker environment. Couldn’t be simpler.But how to use it to run a one-off tool written in Go? This article on the official Docker blog gave me everything I needed to know.
First step: run the
go get
command in a brand new Docker container, like so:This runs the
go get
command in a new instance of the official golang container. If you’ve never used the container before, Docker will download everything it needs before executing the rest of the command.Once this command finishes, we have a container with the Go program compiled and installed in it. But how to run it?
We can “commit” the container to freeze it into a new image that bakes in the command. Here’s how to do that:
The nested
docker ps -lq
command outputs the container ID. The outer docker commit
command then creates a new image freezing those latest changes.Having frozen the container, we can run the command like this:
And the command runs, exactly as if I’d installed it without using Docker at all.
One last puzzle: the above command worked for load testing externally hosted URLs, but I also wanted to try running it against a web server running on port 8000 on my Mac itself. Running
hey
against http://localhost:8000/
didn’t work inside the container. Instead, I ran ipconfig getifaddr en0
to find the local network IP address of my Mac and then ran hey
against that IP address (thanks again, Stack Overflow):For me, this use-case illustrates a huge part of the value of Docker: it lets you execute tools written in basically anything without having to pollute your laptop with environment junk.
Running commands against files
I decided to use this technique to try out this Go minify tool by Taco de Wolff. Building the tool into a container used the same pattern:
Running the command this time is a bit harder, because it needs access to files on my filesystem. I can give it access by mounting my current directory as part of the
docker run
command, like so:Running this minifies the contents of the
all.css
file in my current directory and outputs the result to standard out. If I want to save it I can redirect it to a file like so:Posted 5th November 2017 at 3:50 am · Follow @simonw on Twitter
Using the Go extension for Visual Studio Code, you get language features like IntelliSense, code navigation, symbol search, bracket matching, snippets, and many more that will help you in Golang development.
You can install the Go extension from the VS Code Marketplace.
Golang For Mac
IntelliSense
Auto completions
As you type in a Go file, you can see IntelliSense providing you with suggested completions. This even works for members in current, imported, and not yet imported packages. Just type any package name followed by
.
, and you will get suggestions for the corresponding package members.By setting
go.autocompleteUnimportedPackages
to true
in your settings, you can also get suggestion for packages that you could import. Select one of these suggestions and an import to the selected package will be added to your file.Tip: Use ⌃Space (Windows, Linux Ctrl+Space) to trigger the suggestions manually.
Hover Information
Hovering on any variable, function, or struct will give you information on that item such as documentation, signature, etc.
By default, the extension uses
godef
and godoc
to get this information. You can choose to use gogetdoc
instead by changing the setting go.docsTool
in your User or Workspace Settings.Signature help
When you open the
(
while calling a function, a pop-up provides signature help for the function. As you keep typing the parameters, the hint (underline) moves to the next parameter.Tip: Use ⇧⌘Space (Windows, Linux Ctrl+Shift+Space) to manually trigger the signature help when the cursor is inside the
()
in the function call.The extension's signature help also uses
godef
and godoc
. You can choose to use gogetdoc
instead by changing the setting go.docsTool
in your User or Workspace Settings.Code navigation
Code navigation features are available in the context menu in the editor.
- Go To DefinitionF12 - Go to the source code of the type definition.
- Peek Definition⌥F12 (Windows Alt+F12, Linux Ctrl+Shift+F10) - Bring up a Peek window with the type definition.
- Go to References⇧F12 (Windows, Linux Shift+F12) - Show all references for the type.
You can navigate via symbol search using the Go to Symbol commands from the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)).
- Go to Symbol in File - ⇧⌘O (Windows, Linux Ctrl+Shift+O)
- Go to Symbol in Workspace - ⌘T (Windows, Linux Ctrl+T)
You can also navigate back and forth between a Go file and its test implementation using the Go: Toggle Test File command.
Build, lint, and vet
On save, the Go extension can run
go build
, go vet
, and your choice of linting tool (golint
or gometalinter
) on the package of the current file. You can control these features via the settings below:go.buildOnSave
go.buildFlags
go.vetOnSave
go.vetFlags
go.lintOnSave
go.lintFlags
go.lintTool
go.testOnSave
The errors and warnings from running any/all of the above will be shown red/green squiggly lines in the editor. These diagnostics also show up in the Problems panel (View > Problems).
Formatting
You can format your Go file using ⇧⌥F (Windows Shift+Alt+F, Linux Ctrl+Shift+I) or by running the Format Document command from the Command Palette or the context menu in the editor.
By default, formatting is run when you save your Go file. You can disable this behavior by setting
editor.formatOnSave
to false
for the [Go] language. You can change this using your json setting filesYou can choose among three formatting tools:
gofmt
, goreturns
, and goimports
by changing the setting go.formatTool
.Test
There are many test-related commands that you can explore by typing 'Go: test' in the Command Palette.
The first three above can be used to generate test skeletons for the functions in the current package, file or at cursor using
gotests
. The last few can be used to run tests in the current package, file or at cursor using go test
. There is also a command for getting test coverage.Import packages
Run the command Go: Add Import to get a list of packages that can be imported to your Go file. Choose one and it will get added in the import block of your Go file.
Rename symbols
Golang Pdf
You can rename symbols using F2 or by running the Rename Symbol command in the context menu in the editor.
Debugging
The Go extension lets you debug Go code as well. You will need to install the Delve debugger manually as a prerequisite. Read Debug Go programs in VS Code for setup steps, information on remote debugging and a troubleshooting guide.
Next steps
This has been a brief overview showing the Go extension features within VS Code. For more information, see the details provided in the Go extension README.
To stay up-to-date on the latest features/bug fixes for the Go extension, see the CHANGELOG.
If you have any issues or feature requests, feel free to log them in the Go extension repo.
If you'd like to learn more about VS Code, try these topics:
- Basic Editing - A quick introduction to the basics of the VS Code editor.
- Install an Extension - Learn about other extensions are available in the Marketplace.
- Code Navigation - Move quickly through your source code.