Introduction to GO (GoLang # 1)

Introduction to GO (GoLang # 1)

Β·

3 min read

GO Programming Language or GO Lang was developed by Google in 2006 and Open-Sourced in 2009.

It is a statically typed, compiled language that has vast applications in the cloud native space. It is a backend / server-side language.

Why need a new Language πŸ€”?

Go was designed keeping in mind the evolving infrastructure

  • cloud Infrastructure changed a lot
  • multi-core processors became common
  • big networked computational clusters
  • scalable and distributed
  • more capacity

While other existing languages could not fully take advantage of this, GO came to the rescue. GO was designed to run on multiple cores and built to support concurrency.

Concurrency - Doing multiple tasks at the same time

Ex - "Watching a video on YouTube while also subscribing, commenting, and liking other comments" or "editing a word document online with 2 of your friends at the same time"

Main Use Cases of Go πŸ™„

  • for performant applications
  • running on scaled distributed systems

Characteristics of Go 🧐

  • simple and readable syntax of a dynamically typed language like Python
  • efficiency and safety of a lower-level statically typed language like C++
  • used in server-side or backend
    • microservices
    • database services
    • web applications
    • etc.

Also, some of the most popular technologies in the Cloud-Native Space like Docker 🐳 and Kubernetes ⎈ are written in GO.

Installing GO

Download your platform-specific binary from - go.dev/dl and install it.

goins_1.png

goins_2.png

To verify the installation, go to your terminal and type and enter "go".

You should see an output if the installation was done correctly.

verify.png

I am using VSCode as my code editor, you can install an extension named Go (by - Go Team at Google) to make life a little easy.

ext.png

Click on install if any pop-up shows up.

Hello World

Writing your first Golang program

  • create a folder in which you will keep your code (i made one named GO-Hello)

  • create a file named main.go

  • in golang we have to first initilaize our project. To do so, open your integrated terminal in VS Code and use the command

    • go mod init module-name

      • it will create a file named go.mod
go mod init GO-Hello

init.png

struc.png

  • all our code must belong to a package ( main ).

The package main tells the Go compiler that the package should compile as an executable program instead of a shared library(more on that in the upcoming parts)

package main

import "fmt"

func main() {
    fmt.Print("Hello World")

}
  • for one go application / program, you can have only one main function as it is the entrypoint to your code
  • running your GO Code

    • go run filename.go
go run main.go

run.png

CongratulationsπŸŽ‰, you have just written your first Golang program and learned a bit about the language.

You can also visit my GitHub repository for more code samples and notes 😎.

Thank you for reading, hope you liked it πŸ˜… and see you in the next one.

Did you find this article valuable?

Support Yash Dhasmana by becoming a sponsor. Any amount is appreciated!

Β