Go: Program Structure

Go program is designed into various section. The following sections defines a Go program.

  1. Package Declaration
  2. Import statement
  3. Functions
  4. Variables
  5. Statements and Expression
  6. Comments

Now let us write a hello world program in go language.

package main /*Package declaration*/
import "fmt" /*Import statement*/
func main() { /*Function declaration*/
  /*Our hello world program*/
  /*The below line when executed will print "Hello World!"*/
  fmt.Println("Hello world!")
}

Save the above program in a file hello-world.go. Now to run the above program, go to terminal and type

$ go run hello-world.go

Output:

Hello world!

Recent Posts

Categories

GiottoPress by Enrique Chavez