About
Package in Go.
Go treats files in a single directory as belonging to one package as long as they all have the same name in their package declarations.
Go code is organized into packages (similar to libraries or modules).
Package names are always in lower case.
Articles Related
Properties
Name
The first statement in a Go source file must be
package name
Go's convention is that the package name is the last element of the import path. See below.
Executable commands must always use package main.
Import Path (Package Id)
An import path is a string that uniquely identifies a package.
A package's import path corresponds to its location:
- inside a workspace
- or in a remote repository
The packages from the standard library are given short import paths such as “fmt” and “net/http”.
import (
"fmt"
"base-path/package-name/go-source-file"
)
The import statement tell the compiler what packages are needed by the source file.
Base Path
The base path is the root path of (custom|user) package (not standard library or other external libraries)
Description
By convention, each package is described in a comment immediately preceding its package declaration.
Management
Dependency Manager
- godep
- glide
- govendor
- gopm
- gb
Installation
go get base_path/package-name
where:
Search / Analytics
- https://golang.org/pkg Index of the standard library packages
- https://godoc.org Packages contributed by the community