Getting Started With GoLang For .NET Developers

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?

  1. Open Source Programming Language.
  2. It supports concurrency,
  3. Compiles into machine code.
  4. It has support for Garbage collector,
  5. Supports runtime reflection.
  6. “It's a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.”
  7. It is cross-platform.

Websites: https://golang.org/ and https://go.dev/

Installation

Go Lang is cross-platform. It comes in 3 platforms:

  1. Linux
  2. Max
  3. 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,

  1. VS Code, VS Code Extension link - https://marketplace.visualstudio.com/items?itemName=golang.go
  2. GoLand - https://www.jetbrains.com/go/
  3. 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

  1. If you don’t have VS Code already installed. You can download it from here https://code.visualstudio.com/.
  2. Now, install VS Code extension with Name “Go” or from the link, https://marketplace.visualstudio.com/items?itemName=golang.go

    Getting Started with GoLang for .NET Developers
     
  3. Once installation is completed, check in VS Code Terminal “go version”.

    Getting Started with GoLang for .NET Developers

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.

Getting Started with GoLang for .NET Developers

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!!


Similar Articles