ryn*_*nop 18 go protocol-buffers protoc go-modules
我分叉一个前进模块,并希望用叉子在我的项目使用版本控制模块通过v1.12。我的代码不在我的GOPATH.
我的项目go.mod:
module github.com/me/myproj
go 1.12
require (
go.larrymyers.com/protoc-gen-twirp_typescript v0.0.0-20190605194555-ffbfe407b60f
)
replace go.larrymyers.com/protoc-gen-twirp_typescript => github.com/rynop/protoc-gen-twirp_typescript master
Run Code Online (Sandbox Code Playgroud)
protoc-gen-twirp_typescript 是一个工具protoc,所以这是我的tools.go:
// +build tools
package tools
import (
// protocol buffer compiler plugins
_ "github.com/golang/protobuf/protoc-gen-go"
_ "github.com/mwitkow/go-proto-validators/protoc-gen-govalidators"
_ "github.com/twitchtv/twirp/protoc-gen-twirp"
_ "github.com/rynop/protoc-gen-twirp_typescript"
)
Run Code Online (Sandbox Code Playgroud)
当我运行go mod tidy下载依赖项时,出现此错误:
go: finding github.com/rynop/protoc-gen-twirp_typescript master
go: finding github.com/rynop/protoc-gen-twirp_typescript latest
go: github.com/rynop/protoc-gen-twirp_typescript@v0.0.0-20190618203538-a346b5d9c8fb: parsing go.mod: unexpected module path "go.larrymyers.com/protoc-gen-twirp_typescript"
Run Code Online (Sandbox Code Playgroud)
为什么我收到这个错误?我认为中的替换指令go.mod允许分叉模块 go.mod保持不变。
typ*_*182 15
你有以下几点replace:
replace go.larrymyers.com/protoc-gen-twirp_typescript => github.com/rynop/protoc-gen-twirp_typescript master
如果我遵循了,这是有效的 replace originalname => forkname
我认为问题在于您使用 fork 的名称而不是原始名称导入:
import (
// protocol buffer compiler plugins
_ "github.com/golang/protobuf/protoc-gen-go"
_ "github.com/mwitkow/go-proto-validators/protoc-gen-govalidators"
_ "github.com/twitchtv/twirp/protoc-gen-twirp"
_ "github.com/rynop/protoc-gen-twirp_typescript" <<<< PROBLEM, using fork name
)
Run Code Online (Sandbox Code Playgroud)
您看到的错误消息似乎是go抱怨该问题的命令。
我怀疑如果您在导入语句中使用原始名称它会起作用:
import (
...
_ "go.larrymyers.com/protoc-gen-twirp_typescript" <<<< original name
)
Run Code Online (Sandbox Code Playgroud)
您还应该运行go list -m all以查看最终选择的版本,包括它显示 anyreplace和exclude指令的结果。