Go build 命令不会创建相同的二进制文件,它是错误的 cmd/ :
首先好的(~/go/ 之前为空):
$ find .
.
./cmd
./cmd/api
./cmd/api/main.go
我建立 :
$ cd cmd/api; go build -v main.go
get "gopkg.in/yaml.v2": found meta tag get.metaImport{Prefix:"gopkg.in/yaml.v2", VCS:"git", RepoRoot:"https://gopkg.in/yaml.v2"} at //gopkg.in/yaml.v2?go-get=1
get "golang.org/x/sys": found meta tag get.metaImport{Prefix:"golang.org/x/sys", VCS:"git", RepoRoot:"https://go.googlesource.com/sys"} at //golang.org/x/sys?go-get=1
get "gopkg.in/check.v1": found meta tag get.metaImport{Prefix:"gopkg.in/check.v1", VCS:"git", RepoRoot:"https://gopkg.in/check.v1"} at //gopkg.in/check.v1?go-get=1
get "golang.org/x/text": found meta tag get.metaImport{Prefix:"golang.org/x/text", VCS:"git", RepoRoot:"https://go.googlesource.com/text"} at //golang.org/x/text?go-get=1
get "golang.org/x/tools": found meta tag get.metaImport{Prefix:"golang.org/x/tools", VCS:"git", RepoRoot:"https://go.googlesource.com/tools"} at //golang.org/x/tools?go-get=1
go: downloading github.com/gin-gonic/gin v1.6.3
etc ....
go: finding golang.org/x/sys v0.0.0-20200116001909-b77594299b42
结果 :
$ ls -l
total 14940
-rwxr-xr-x 1 fr3 nobody 15290667 May 12 14:00 main
-rw-r--r-- 1 fr3 nobody 619 May 12 13:41 main.go
现在使用 cmd/ :
$ find .
.
./cmd
./cmd/api
./cmd/api/main.go
我使用 mod 命令:
$ go mod init api
go: creating new go.mod: module api
$ go mod vendor
go: finding github.com/gin-gonic/gin v1.6.3
go: downloading github.com/gin-gonic/gin v1.6.3
etc ....
go: extracting github.com/go-playground/locales v0.13.0
vendor/ 被创建:
ls -l
total 16
drwxr-xr-x 3 fr3 nobody 4096 May 12 13:42 cmd
-rw-r--r-- 1 fr3 nobody 61 May 12 14:07 go.mod
-rw-r--r-- 1 fr3 nobody 3872 May 12 14:07 go.sum
drwxr-xr-x 5 fr3 nobody 4096 May 12 14:07 vendor
$ mkdir target
go build -o target/api cmd/api
$ ls -l target/
total 5912
-rwxr-xr-x 1 fr3 nobody 6052601 May 12 14:08 api
慕田峪4524236
拉莫斯之舞
相关分类