Package is the unit of go language
In GO language, Package is the Basic unit while other language’s unit usually be file. For example,we have two hello World software in different language , Their directory tree is :
- GO
1 | root : |
- Python
1 | root : |
In go, the syntax to use hello world func is :
1 | import root.hello |
In Python, the syntan to use hello world func is :
1 | import root.hello.hello |
What is Package
Package is a directory which including .go source file. Some features of package in Go:
Features:
Package name is match with directory name. If your package is called logger, your directory may be like:
1
$GOPATH/src/github.com/yourname/logger
Package name is recommend as lower case.
Package names, and thus the package’s directory, **should contain only letters, numbers **if you must, but absolutely no punctuation. Package name is part of type , func , var , const which export by this package.
All files in a package’s directory should have the same package declaration.
- Testing file is a exception; For testing, your test files, those ending with
_test.go
, may declare themselves to be in the same package, but with_test
appended to the package declaration.
- Testing file is a exception; For testing, your test files, those ending with
Main package
Main package is actually commands, these carry the declaration of package main
. It also conforms to the previous package specification,