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.
Run the program as:
chetan:go-work chetan$ go run hello.go hello, world
And done, we have a simple working Go program! 🙂
Cool, now let’s talk about the editors. There are multiple editors that support Go, here are a few of them:
- vim-go – plugin provides Go programming language support
- Atom – Go-Plus is an Atom package that provides enhanced Go support
- Visual Studio Code – Go extension provides support for the Go programming language
In this blog, we will setup Go on Visual Studio Code:
- Download and install Visual Studio Code from https://code.visualstudio.com/
- Click on the ‘Extensions’ icon and search Go for the extension
- Use the extension by Microsoft and install it (I think this will also install delve to debug the Go apps)
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.