duanjiwei1283 2019-06-19 15:20
浏览 132
已采纳

如何使用带有版本化的Go模块的分叉模块(v1.11 +,GO111MODULE = on)

I forked a go module, and want to use the fork in my project that uses versioned modules via v1.12. My code is not inside my GOPATH.

My project's 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

protoc-gen-twirp_typescript is a tool for protoc, so here is my 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"
)

When I run go mod tidy to download my dependencies, I get this error:

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"

Why am I getting this error? I thought the replace directive in go.mod allows for the forked modules go.mod to stay untouched.

  • 写回答

2条回答 默认 最新

  • douye9822 2019-08-01 21:12
    关注

    You have the following replace:

    replace go.larrymyers.com/protoc-gen-twirp_typescript => github.com/rynop/protoc-gen-twirp_typescript master

    which if I've followed, is effectively replace originalname => forkname

    I think the issue is that you are importing using the name of the fork, rather than the original name:

    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
    )
    

    The error message you see seems to be the go command complaining about that.

    I suspect it would work if you used the original name in the import statement:

    import (
        ...
        _ "go.larrymyers.com/protoc-gen-twirp_typescript"   <<<< original name
    )
    

    You should also run go list -m all to see the final selected versions, including it shows the outcome of any replace and exclude directives.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何提取csv文件中需要的列,将其整合为一篇完整文档,并进行jieba分词(语言-python)
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?