Package basics
Context
Section titled “Context”Every Go file belongs to a package. A package is a collection of Go files in the same directory that are compiled together. The main package defines an executable program. Other packages are reusable libraries.
Example
Section titled “Example”Create two files in the same directory: main.go and math.go with package mymath.
Code example
Section titled “Code example”// math.gopackage mymath
func Add(a, b int) int { return a + b}// main.gopackage main
import ( "fmt" "mymath")
func main() { fmt.Println(mymath.Add(3, 4))}Output
Section titled “Output”7