Import Functionality
This lesson introduces a basic component of Go program, i.e., packages.
We'll cover the following...
Packages
A library, module, or namespace in any other language is called a package. Packages are a way to structure code. A program is constructed as a package which may use facilities from other packages. A package is often abbreviated as ‘pkg’.
Every Go file belongs to only one package whereas one package can comprise many different Go files. Hence, the filename(s) and the package name are generally not the same. The package to which the code-file belongs must be indicated on the first line. A package name is written in lowercase letters. For example, if your code-file belongs to a package called main, do the following:
package main
A standalone executable belongs to main. Each Go application contains one main.
An application can consist of different packages. But even if you use only package main, you don’t have to stuff all code in 1 big file. You can make a number of smaller ...