Getting Started With Go: Beginner Tutorial

Getting Started With Go: Beginner Tutorial

Create a file named main.go in your project directory.

From the above code, you should be having the following questions.

  1. How do I run this code?
  2. What does package main mean?
  3. What does import fmt mean?
  4. What does func mean?
  5. How is the main.go file organized?

How do I run this code

Open the terminal and browse to your project folder containing main.go file

Execute your main.go program using the following command.

Following are the available commands in Go. In that, we have used run command to execute our hello world program.

What does package main mean:

Every go program must start with a package declaration. It is for code organization and reusability.

There are two types of packages

  1. Executable: Can be executed directly through a command line or a click. This is normally used for creating small utilities. Each executable package is meant for some functionality. Once such example is creating a database backup.
  2. Reusable: Reusable packages are helper functions or reusable codes or a library that can be called within other program files.

How do you know you are creating an executable package or reusable package?

If your package declaration starts with main, it means you are creating an executable package. Any name other than main will be a reusable package.

What does import fmt mean?

It imports a package named fmt. This package helps in printing text to the standard output. It is a standard library. You can view the list of standard libraries available from here

func main()

func represent function. The go program execution starts from the main function. This main function will always reside in the main package file.

fmt.Println(“Hellow World Scripties”)  prints the text mentioned inside the quotes to the standard output.


golang variable tutorial

A variable is an identifier for allocating memory to store a specific value. Variable Declaration Variable…

Read more

The Best Tutorials & Tips to Speedup Your DevOps Workflow.

Created by Bibin Wilson.