Go Package, import, and visibility
Packages
Packages are used to categorize our program so that it can be easy to maintain. Every go-file belongs to some package. Each Go application must have "main" package so that it can be compiled.
An application can consist of different packages. Many different .go file can belong to one main package.
We can save Go program by any name but it must have main package. The package name should be written in lowercase letters.
If a package is changed and recompiled, all the client programs that use this package must be recompiled too!
Import
A Go program is linked to different packages through the import keyword.
The package names are enclosed within double quotes "". Import loads the public declarations from the compiled package, it does not insert the source code.
0 comments:
Post a Comment