The first Go program starts with Hello World

package main // The package that acts as the entry to the program

import "fmt"

func main(a)  {  // function as program entry
	fmt.Println("Hello World")}Copy the code

Package main: must be declared. Package must be followed by main, not by another name or the name of the directory where the file is located. If you write the name of the directory where the file is located, you will get an error

package src

import "fmt"

func main(a)  {
	fmt.Println("Hello World")}Copy the code

Go run: cannot run non-main package


Func main() {} : must also be written, if not “func main”, the following is an example of what would happen

package main

import "fmt"

func ShiLi(a)  {
	fmt.Println("Hello world")}Copy the code

# command-line-arguments runtime.main_main·f: relocation target main.main not defined runtime.main_main·f: undefined: “main.main”


Import “FMT” : Import code dependencies (some of the code is written by someone else, we don’t need to rewrite it ourselves, just import the code written by someone else into our project)