A new product!

Social Media Toolkit

Download our all in one automation tool for various social media websites.

Gopher

A Basic Program in Go

Published on 29 March 2020
Last Updated on 29 March 2020

Given below is a simple example of a basic go program.

Simple program

Program:

package main

import "fmt"

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

How to run above program

Above program can be saved to a file, for example the name of the file can be basic_program/main.go, after the file is saved.

It can be executed using following command:

go run basic_program/main.go

Alternatively, we can also build our programs as a binary file and execute the binary file using the go build command.

Program output

Above program produces following output:

Hello World!

Program Description

Above program demonstrates how a basic go program might look like. A go command line program typically has an import statement, followed by variable declaration and a main function.

main() Function

main() function serves as an entry point to every Go program.