Packages
A package name is the name of the directory contained in src directoryA package declaration is the name declared on top of a go file.
Package declaration which should be first line of code like package main in above example, can be different than package name.
go build <pkg_name>/ go install <pkg_name>; looks for <pkg_name> which is a sub-directory name.
Go first searches for package directory inside GOROOT/src directory and if it doesn’t find the package, then it looks for GOPATH/src
go install <pkg_name> command scans any file with main package declaration inside given package directory. If it finds a file, then Go knows this is an executable program and it needs to create a binary file.
If a package does not contain a file with main package declaration, then Go creates a package archive (.a) file inside pkg directory.
No comments:
Post a Comment