package main
import humanize "github.com/dustin/go-humanize"import"fmt"funcmain() {
fmt.Println("hello world")
fmt.Printf("That file is %s.\n", humanize.Bytes(82854982)) // That file is 83 MB.
fmt.Printf("You're my %s best friend.\n", humanize.Ordinal(193)) // You are my 193rd best friend.
fmt.Printf("You owe $%s.\n", humanize.Comma(6582491)) // You owe $6,582,491.
}
編譯的時候會出現以下錯誤。
1
2
3
4
[ykyuen@camus glide-example]$ go build -o hello
main.go8: cannot find package "github.com/dustin/go-humanize" in any of:
/home/ykyuen/tools/go1.8.4/src/github.com/dustin/go-humanize (from $GOROOT)
/home/ykyuen/go/src/github.com/dustin/go-humanize (from $GOPATH)
[ykyuen@camus glide-example]$ glide create
[INFO] Generating a YAML configuration file and guessing the dependencies
[INFO] Attempting to import from other package managers (use --skip-import to skip)
[INFO] Scanning code to look for dependencies
[INFO] --> Found reference to github.com/dustin/go-humanize
[INFO] Writing configuration file (glide.yaml)
[INFO] Would you like Glide to help you find ways to improve your glide.yaml configuration?
[INFO] If you want to revisit this step you can use the config-wizard command at any time.
[INFO] Yes (Y) or No (N)?
Y
[INFO] Looking for dependencies to make suggestions on
[INFO] --> Scanning for dependencies not using version ranges
[INFO] --> Scanning for dependencies using commit ids
[INFO] Gathering information on each dependency
[INFO] --> This may take a moment. Especially on a codebase with many dependencies
[INFO] --> Gathering release information for dependencies
[INFO] --> Looking for dependency imports where versions are commit ids
[INFO] No proposed changes found. Have a nice day.
[ykyuen@camus glide-example]$ glide install
[INFO] Downloading dependencies. Please wait...
[INFO] --> Found desired version locally github.com/dustin/go-humanize bb3d318650d48840a39aa21a027c6630e198e626!
[INFO] Setting references.
[INFO] --> Setting version for github.com/dustin/go-humanize to bb3d318650d48840a39aa21a027c6630e198e626.
[INFO] Exporting resolved dependencies...
[INFO] --> Exporting github.com/dustin/go-humanize
[INFO] Replacing existing vendor dependencies
再一次編譯並運行
1
2
3
4
5
6
[ykyuen@camus glide-example]$ go build -o hello
[ykyuen@camus glide-example]$ ./hello
hello world
That file is 83 MB.
You're my 193rd best friend.
You owe $6,582,491.