Setup Go Development Environment with Atom Editor

Atom, an editor from Github, is an excellent editor with a plugin ecosystem for most languages and tools. It comes with built-in syntax highlighting for Go code.

image06
We will going to add additional plugins to make our Go Development easier inside of Atom.

First up, we are go to install and setup the Atom Editor with the required plugins. Follow these steps to install and setup Atom Editor.

  1. Download and install the Atom Editor from https://atom.io
  2. Ensure you have already installed Go on the same development machine.
  3. Make sure that GO binaries are available in the PATH and that GOPATH Environment variable has been set up too.
  4. Make sure that you are connected to the Internet since the plugins will be downloaded from external repositories.
  5. Launch Atom.
  6. Go to Preferences/Settings.
  7. Click on +Install
  8. In the Search packages search box, enter the following: go-plus. You should see one result come up as shown below:

    image03
  9. Click on Install and let it complete.
  10. Go ahead and search + install the following plugins too: autocomplete-go
  11. Close Atom Editor and launch it again.
  12. Go to Packages → Go Plus as shown below and select Get Missing Tools. This will download the rest of the tools for you.

    image04 
  13. To validate the setup, go to Packages → Go Plus and Display Go Information. You should see a summary display as shown below. Notice that it has detected your Go binaries and also the GOPATH information.

    image05
  14. Finally we want to install a terminal/console in Atom Editor itself , so that you can run your Go code directly from within the editor itself and you do not need to go outside. Go ahead and search + install the following plugin : terminal-plus. Go ahead and install it.
  15. Restart your Atom Editor again.

 

Atom Editor in Action

Let us now validate our Atom Editor setup that we did and what we have got in return for all the plugins that we installed so far.

 

Assuming that you have launched the Atom Editor, the first step to do is to add a Project folder. Assuming that you have setup the GOPATH for your Go Projects, you can select a folder in which you are going to keep your project files.

 

  1. In the Atom Editor, go to File → Add Project Folder… This will bring up a Folder selection dialog and you can point it to the root of your application.
  2. Create a new file named main.go as follows and you can put in the standard Hello World program.
  3. While typing do notice that auto-complete is now available (try Ctrl-Space too):

    image02 
  4. On saving a file at any time, the file is checked for any compile time issues and several other things like automatically adding the imports or removing them if you are not using them is taken care of. That’s pretty neat. Go ahead and try that.
  5. For e.g. if you make some basic errors in the Go file and you save the file, you will see the errors show up below as shown below:

    image01 
  6. To further tweak what is happening under the hood by the go-plus plugin, you should go to Preferences/Settings, then Installed Packages, search for go-plus and click on Settings. This will show you easy to understand settings that it uses to do its work, for e.g. what tool to run on save, etc.
  7. Now let us take a look at how to run the Go application from within the Atom Editor itself and via the terminal-plus plugin that we just installed.
  8. First up, go to Preferences/Settings and then Installed Packages, search for terminal-plus and go to the Settings. Scroll down and you should see a setting for the Working Directory. Ensure that it is set to Project.
  9. Now you can launch the Terminal at any time via the Ctrl + ` key combination. You can also toggle it with this combination.

    image00 
  10. On launching the terminal, you should see it come up and you can validate if you are in the correct folder via the pwd command.
  11. You can now use standard Go commands to run your application. For e.g. go run as shown below:

    image07


Happy Go Programming with the Atom Editor.

 

Advertisements

One thought on “Setup Go Development Environment with Atom Editor

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s