Go - Program Structure
Go - Program Structure : basic building blocks of Go programming language.we will discuss the minimum structure of Go programs so that we can take it as a reference in subsequent chapters.
Hello World ExampleThe program basically consists of Go :
- Package Declaration
- Import Packages
- Statements and Expressions
package deal principal import "fmt" func principal() /* This is my first example application. */ fmt.Println("Hello, World Welookups!")
Let us test the various parts of the above application :
The first line of the program pack main characterizes the package name wherein this application need to lie.The main package is the starting point to run the program.
func vital() is the essential capacity where this framework execution starts.
The next line import "fmt" is a preprocessor command which tells the Go compiler to include the files lying in the package fmt.
The next line func main() is the main function where the program execution begins.
The ensuing line/*...*/is ignored by means of the compiler and it is there to include remarks inside the program.
Here the capital P of Println method In Go language, a name is exported if it starts with capital letter.
Executing a Go ProgramGive us a chance to save about how to source code in a file, compile it, and at last execute this framework.
Open a text editor and add the above-mentioned code.
Save the file as hello.go
Open the command prompt.
Go to the directory where you saved the file.
Type go run hello.go and press enter to run your code.
If there are no errors in your code, then you will see "Hello World!" printed on the screen.
$ go run hello.go Hello, World!