Welcome To Golang By Example

Hello World in Go (Golang)

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

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