I have been working with Go (also known as Golang) for some time now, and I must tell you that the more I work with it, the more I like it. And, that's the inspiration to set me on this path of sharing my learning about Go. That said, here is what we will be talking about in this article:
- Introduction to Go
- Environment setup
- Hello, World! - following the tradition
Introduction to Go
Go is a general-purpose language, which was designed with systems programming in mind. At first Go feels more or less like C or C++, but it's certainly more than that. Three key aspects that make Go standout are, that it is compiled, garbage collected and above all it has explicit support for concurrent programming.
Go is compiled. When we say so, it's important to understand that it is compiled down to the processor level. This means that when we compile our code, it is compiled into a code that runs directly on the processor.
Garbage Collected
In general, garbage collection means that the memory is managed for you. Go free up a developer from worrying about allocating or freeing memory manually. In Go, garbage collection is very fast as compared to other programming languages that have built in garbage collection, where it can create some latency in the application at an unpredictable time.
Concurrent Programming
Go is concurrent, and this concurrency is built right into the language. The <em>Go routines</em> allow us to handle concurrency by communicating through messages or passing the data instead of sharing it. This gives Go, the capability of taking advantage of modern processor where we have multiple cores and multiple processors almost everywhere.
Environment Setup
To setup the environment and get started with Go, the first thing we need is to install Go and there is no better place (with description) than Go's Downloads page. Once we select the package based on our OS, we land on a page that describes the steps to setup Go in the PATH environment variable, followed by setting the GOPATH.
Go Installation Directory
When we install Go, it creates a directory c:\go on Windows and /usr/local/go in UNIX. This is where all the necessary binaries are kept by Go to make command line tools, compiler and standard library work. So, when we import a package from Go's standard library, Go looks for that package in this directory.
If we want to change the installation directory of Go, we can very well do so. However, to let Go know about the change, we are required to update the value of GOROOT variable which is by default set to default installation directory. On Windows, we can do so by updating the GOROOT environment variable, and on UNIX we can edit the ~/.bash_profile and set the GOROOT as,
- // edit the ~/.bash_profile file
- export GOROOT=/usr/local/custom-go
I would suggest, not to change the Go root, until it's really required and is your last resort.
Go Workspace
A workspace is a way to facilitate project management in Go. A workspace is simply a directory on our system, where Go looks for source code files, manages dependency packages and build distribution binary files. We can have as many workspaces as we want, however, we must ensure that the GOPATH environment variable must point to current working workspace directory.


Sourabh SomaniPosted Dec 6, 2018, 12:21 AM
Thank You Gaurav. Happy to see your first article. Looking for more articles to learn GO from you :)
Mahesh ChandPosted Dec 5, 2018, 9:16 AM
Thank you, Gaurav. Appreciate your efforts to taking this initiative bringing Go to C# Corner. Best