Golang Hello World!

Well, in the last blog we installed Go on our Mac and Ubuntu systems, now it’s time to run our first program – program to display hello, world and learn about using the Visual Studio Code editor.

Go Hello World

When you have go installed, running a Go script is like running any other program for an interpreted language. Like in Python, we run python app.py in Go we can run a script as go run hello.go. Let’s write a simple Go program to display hello, world on the terminal. Open an file hello.go and type in below source code.

At a high level – package keyword indicates this file can be used as a package, main() is the method that is called when the program is run.

Source code:

Screen Shot 2018-12-04 at 11.51.33 AM

 

Run the program as:

chetan:go-work chetan$ go run hello.go
hello, world

And done, we have a simple working Go program! 🙂

Go Editors

Cool, now let’s talk about the editors. There are multiple editors that support Go, here are a few of them:

  1. vim-go – plugin provides Go programming language support
  2. Atom – Go-Plus is an Atom package that provides enhanced Go support
  3. Visual Studio Code – Go extension provides support for the Go programming language

In this blog, we will setup Go on Visual Studio Code:

  1. Download and install Visual Studio Code from https://code.visualstudio.com/
  2. Click on the ‘Extensions’ icon and search Go for the extension
  3. Use the extension by Microsoft and install it (I think this will also install delve to debug the Go apps)

Screen Shot 2018-12-04 at 12.14.56 PM

That’s it! So now we have an editor setup and we can also run a simple Go program from the terminal.

In the next blog, we will look at the Go project structure and the dev tools that will be useful during development.

 

 

 

Advertisements