This is a creation in Article, where the information may have evolved or changed.
Go Language Customization Package
A package is a collection of functions and data. Define a package with the bundle keyword. File name does not need to be associated with package name
Consistent, but your folder must be consistent with the package name, which is important, so for simplicity, the name is the same. The Convention for package names is to use lowercase characters. A Go package can consist of multiple files, but using the same
Package this line. Let's define a package called PAC in the file pac.go.
1 Packages of code:
Package PAC
Import (
"FMT"
)
Func Printt (x string) {
Fmt. PRINTLN (x + "Love Liu Hanlin")
}
Func printtt (x string) {
Fmt. PRINTLN (x + "Love Liu Hanlin")
}
program code to invoke the package
Package Main
Import (
"FMT"
"PAC"
)
Func Main () {
pac.Printt("凯凯")
}
3 in your $goroot/src/pkg/pac/directory into your package file
% Go Build
% go Install
4 in your work Gopath directory
Go Build Demao.go
Demao.exe
Run results
Kaikai Love Liu Hanlin
License
Copyright (c) qiniu.com
Based on the MIT protocol release:
- Www.opensource.org/licenses/MIT