dep was the “official experiment.” The Go toolchain, as of 1.11, has (experimentally) adopted an approach that sharply diverges from dep. As a result, we are continuing development of dep, but gearing work primarily towards the development of an alternative prototype for versioning behavior in the toolchain.
The Go community now has the dep project to manage dependencies. Please consider trying to migrate from Glide to dep… Glide will continue to be supported for some time but is considered to be in a state of support rather than active feature development.
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.
}
使用 dep
Gopkg.toml 與 Gopkg.lock
Dep 需要讀取兩個文件,分別是 Gopkg.toml 和 Gopkg.lock 。我們用來 dep init 指令初始化來這兩個文件。
1
2
3
[ykyuen@camus dep-example]$ dep init
Using master as constraint for direct dep github.com/dustin/go-humanize
Locking in master (bb3d318) for direct dep github.com/dustin/go-humanize
[ykyuen@camus dep-example]$ dep ensure -add github.com/leekchan/accounting
Fetching sources...
"github.com/leekchan/accounting" is not imported by your project, and has been temporarily added to Gopkg.lock and vendor/.
If you run "dep ensure" again before actually importing it, it will disappear from Gopkg.lock and vendor/.
package main
import humanize "github.com/dustin/go-humanize"import accounting "github.com/leekchan/accounting"import"math/big"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.
ac := accounting.Accounting{Symbol: "$", Precision: 2}
fmt.Println(ac.FormatMoney(123456789.213123)) // "$123,456,789.21"
fmt.Println(ac.FormatMoney(12345678)) // "$12,345,678.00"
fmt.Println(ac.FormatMoney(big.NewRat(77777777, 3))) // "$25,925,925.67"
fmt.Println(ac.FormatMoney(big.NewRat(-77777777, 3))) // "-$25,925,925.67"
fmt.Println(ac.FormatMoneyBigFloat(big.NewFloat(123456789.213123))) // "$123,456,789.21"
}
並執行它。
1
2
3
4
5
6
7
8
9
10
[ykyuen@camus dep-example]$ go run main.go
hello world
That file is 83 MB.
You're my 193rd best friend.
You owe $6,582,491.
$123,456,789.21
$12,345,678.00
$25,925,925.67
-$25,925,925.67
$123,456,789.21
dep should be perfectly fine at pulling in git submodules in the case you describe. I just replicated what you describe here locally, and the problem isn’t submodules — it’s that there’s no Go code in github.com/go-goracle/goracle/odpi, so it can’t be imported directly.
You likely need to turn off unused-packages pruning in Gopkg.toml for that project specifically, as otherwise dep ensure will automatically remove what appears to be an unused directly (but it seems it’s actually used by cgo).