Download our all in one automation tool for various social media websites.
Given below is a simple example of a basic go program.
Program:
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}
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.
Above program produces following output:
Hello World!
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()
Functionmain()
function serves as an entry point to every Go program.