Getting Started with Go Programming

1 minute read

In this tutorial, you will lean how to get started with Go Programming and write your first Go program.

The Go is an open-source programming language developed by Google. It was created with below 3 things in mind.

  1. Efficient Compilation
  2. Efficient Execution
  3. Ease of Programming

That’s why GoLang is one of the fastest growing and adapting programming language. It’s fast, expressive, easy to read and write code, and lightweight.

Running Go Program

The online Go compiler makes life very easy for GoLang lerner, simply use The Go Playground.

To run Go Program locally on your computer, you can easily install and use it using Install Go on Windows, Linux, and macOS.

Writing your First Go Program

Let’s start with the basic syntax of Go Programming.

// Print "Hello World!" message

package main
import "fmt"

func main() {
  fmt.Println("Hello World!")
}
Note: The line start with "//" is a comment. The comments are used to help user to understand the code, they are completly ignored by the Go compiler.

Let’s understand the different parts of the program.

The main() function

All Go programs start with the main() function.

We must import main package using the package main statement to use this function.

Printing “Hello World!”

We use Println() function to print a String in Go. This Println() function can be used by importing the fmt package using import "fmt" statement.

Take away

The following are the take away from this tutorial.

  1. All Go programs execution start from the main() function.
  2. To use any function from a package, we need to import that package first using import key.
  3. The basic structure of a Go program is as below.
package main

func main() {

}

Now you are good to start with Go Programs. You wrote your first Go Program and executed it with ease.

Updated: