Welcome To Golang By Example

Menu
  • Home
  • Blog
Menu

Hello World in Go (Golang)

Posted on June 28, 2023November 21, 2023 by admin

Let’s see how to write a simple Hello World program in golang. Create a file with an extension.go. Let’s name this file helloworld.go. Below will be the contents of the file.

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

Some points to note about above program

  • Every go file starts with a package name. In the above case it is package main
  • Only main package is executable.
  • The main package will contain a main function that denotes the start of a program
  • We are using the Println function of fmt package to print the Hello World string
fmt.Println("Hello World")

Let’s run this file now. For running, go to the directory which contains this file. Type below command to run the file. What this command will do is compile the go file and immediately run it.

go run helloworld.go

Output

Hello World

Popular Articles

Golang Comprehensive Tutorial Series

All Design Patterns in Go (Golang)

Slice in golang

Variables in Go (Golang) – Complete Guide

OOP: Inheritance in GOLANG complete guide

Using Context Package in GO (Golang) – Complete Guide

All data types in Golang with examples

Understanding time and date in Go (Golang) – Complete Guide

©2023 Welcome To Golang By Example | Design: Web XP