go1.11.2用go mod 将eva-api挪到$GOPATH/src之外,并利用go mod管理包依赖

  1. $ cp -r $GOPATH/src/eva-api ~/works/eva-api
  2. $ go mod init eva-api 会生成文件: go.mod``$ go mod init eva-api 会生成文件: go.mod
  3. $ cat go.mod 只有一行:
module eva-api
  1. $ go build
    报错:
➜ /Users/wenke/works/eva-api git:(wenke) ✗$go build
go: finding github.com/sdming/goh latest
go: finding github.com/sdming/goh/Hbase latest
go: finding github.com/robfig/cron latest
go: finding github.com/astaxie/beego/logs latest
go: finding github.com/astaxie/beego/plugins/cors latest
go: finding github.com/astaxie/beego/context latest
go: finding github.com/astaxie/beego/orm latest
go: finding github.com/astaxie/beego/plugins latest
go: gopkg.in/yaml.v2@v2.2.1: unrecognized import path "gopkg.in/yaml.v2" (https fetch: Get https://gopkg.in/yaml.v2?go-get=1: read tcp 192.168.1.9:63567->35.196.143.184:443: read: connection reset by peer)
go: golang.org/x/net@v0.0.0-20181114220301-adae6a3d119a: unrecognized import path "golang.org/x/net" (https fetch: Get https://golang.org/x/net?go-get=1: dial tcp 6.6.6.6:443: i/o timeout)
go: golang.org/x/crypto@v0.0.0-20181127143415-eb0de9b17e85: unrecognized import path "golang.org/x/crypto" (https fetch: Get https://golang.org/x/crypto?go-get=1: dial tcp 6.6.6.6:443: i/o timeout)
go: error loading module requirements
  1. 解决方法: $ vi go.mod 手动插入第1行下面的内容:
module eva-api

require (
	golang.org/x/crypto v0.0.0-20181127143415-eb0de9b17e85
	golang.org/x/net v0.0.0-20181114220301-adae6a3d119a
)

replace (
	golang.org/x/crypto v0.0.0-20181127143415-eb0de9b17e85 => github.com/golang/crypto v0.0.0-20181203042331-505ab145d0a9
	golang.org/x/net v0.0.0-20181114220301-adae6a3d119a => github.com/golang/net v0.0.0-20181213202711-891ebc4b82d6
)

注意,如果执行下面的命令来修改go.mod会报错,必须手动修改如上,保证require和replace如果多行,都是在括号()里面。感觉应该是go.mod的一个解析错误,需要等golang自己发版更新!:

$ go mod edit -require=golang.org/x/net@v0.0.0-20181114220301-adae6a3d119a
$ go mod edit -require=golang.org/x/crypto@v0.0.0-20181127143415-eb0de9b17e85
$ go mod edit -replace=golang.org/x/crypto@v0.0.00-20181127143415-eb0de9b17e85=github.com/golang/crypto@latest
$ go mod edit -replace=golang.org/x/net@v0.0.0-20181114220301-adae6a3d119a=github.com/golang/net@latest
go: errors parsing go.mod:
/Users/wenke/works/eva-api/go.mod:5: invalid module version github.com/golang/crypto: version must be of the form v1.2.3
  1. 再次执行 $ go build 就可以了。
    同时会生成文件: go.sum

  2. 执行下面命令都正常:

  • $ go test ./tests
  • $ go run main.go
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值