In this article, we are going to start with Go Programming Language. I am a .NET Developer and will try to provide the Jumpstart to Go Lang. Before we begin, let us understand a few things.
Why Go Lang?
GO Language is powered by Google and is Open source. Many google projects are built on Go Lang. It is easy to learn and use. It is scalable and very fast. It’s demand is increasing.
What is Go Lang?
- Open Source Programming Language.
- It supports concurrency,
- Compiles into machine code.
- It has support for Garbage collector,
- Supports runtime reflection.
- “It's a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.”
- It is cross-platform.
Websites: https://golang.org/ and https://go.dev/
Installation
Go Lang is cross-platform. It comes in 3 platforms:
- Linux
- Max
- Windows
Installation Link: https://golang.org/doc/install . This is just like .NET Runtime + .NET SDK.
Check Installation Version, in windows like below,
Open cmd and write,
>> go version
Output
go version go1.17 windows/amd64
Code Editors
For .NET Devs, .NET Core and above can work directly in VS Code using Omnisharp Extension. Similarly, Go Lang can too work in VS Code using Go Extension.
The list of most popular IDEs for Go Lang till the date (4 September 2021) is,
- VS Code, VS Code Extension link - https://marketplace.visualstudio.com/items?itemName=golang.go
- GoLand - https://www.jetbrains.com/go/
- Vim & NeoVim - https://github.com/fatih/vim-go
There are other editors too like Atom, Notepad++, Sublime Textpad, etc. but the one above is the most popular as per Go Lang.
GO LANG In VS Code
- If you don’t have VS Code already installed. You can download it from here https://code.visualstudio.com/.
- Now, install VS Code extension with Name “Go” or from the link, https://marketplace.visualstudio.com/items?itemName=golang.go
- Once installation is completed, check in VS Code Terminal “go version”.
Hello World Console Application
Now, let us create a “Hello World” console application.
go mod init app
Output
go: creating new go.mod: module app
The template “go.module” looks like this,
module app
go 1.17
Open we will create a console.go file.
Write the code below,
package main // This is namespace similar to dotnet namespace
import "fmt" // This is import statement similar to .NET
func main() { //Entrypoint for application just like public static void main()
fmt.Println("Hello From Console App")
}
To run the application we will write “go run .”. It is just like “dotnet run”
The output will be Hello From Console App.
To create the executable we will write “go build”. We will get console.exe as an output. It is just like “dotnet build”. The output will be published in the same directory where it was executed.
Overall the resultant structure looks like the below screenshot. Also, we can check the terminal output sequence commands for reference.
That’s it. This was the beginning of the GoLang Development Series. Do watch out for more articles in the upcoming days.
Thanks for Reading!!