Getting Started with Go Programming

Go is an open-source programming language developed by Google. It was created with these things in mind:

  • efficient execution
  • efficient compilation
  • ease of programming

That's why Go is very fast, expressive (easy to read and write code) and lightweight.


Running Go

The simplest way of running Go code is by using an online Go compiler like The Go Playground.

You can also easily install and run Go programming locally on your computer. For that, visit Install Go on Windows, Linux, and macOS.


Writing Our First Go Program

To get familiar with the basic syntax of Go programming, let's write our first program.

// Print "Hello World!" message

package main
import "fmt"

func main() {
  fmt.Println("Hello World!")
}

Output

Hello World!

Here are the different parts of this program.

1. The main() function

All Go programs start with the main() function.

func main() {
   // code goes here
}

To use this function, we must import the main package first using package main.

Note: The line that starts with // is a comment. Comments are used to help users understand the code; they are completely ignored by the Go compiler.

2. Print a line of text

To print a line of text in Go, we use the fmt.Println() function. The function displays the content from the parentheses ().

To use fmt.Println(), we must import the fmt package first using import "fmt".


Basic Structure of a Go Program

Here are the things to take away from this tutorial.

  1. All Go programs start from the main() function.
  2. The bare minimum code structure of a Go program is:
package main

fun main() {

} 

Frequently Asked Questions

Is the language called Go or Golang?

The official name of the language is plain Go.

The confusion between Go and Golang arose for the following reasons:

  • The official Go website is golang.org; not go.org as this domain was not available.
  • People started using the word Golang for their ease; assuming that Go(lang) is the short form of Go Language.
What are the applications of Go Programming?

Originally, Go was developed to program networking and infrastructure-related stuff.

Today, Go has a wide range of applications like

  • Data science and artificial intelligence.
  • Network Server programming, Web programming.
  • Robotics, Internet of Things, games, and microcontroller programming.
  • Cloud-based applications and server-side applications.
  • Data Scraping.
  • In the future, Golang applications can run in androids as well.
Why should I use Go programming?

Go programming is for you if you are looking for these features:

  • built-in testing
  • support concurrency (can run multiple tasks at a time)
  • fast, simple and lightweight
  • efficient execution
  • efficient compilation
  • ease of programming
  • interfaces to write modular and testable code
  • garbage collection
Is Go an object-oriented language?

Go has features of a structural and object-oriented language. So, the answer can be both yes and no.

Go allows an object-oriented style of programming but it has no type of hierarchy.

Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges