dpzbzp8728 2017-04-25 18:59
浏览 43
已采纳

如何处理区分大小写的导入冲突

I am using a third party library in GoLang that has previously had import paths in different case. Initially a letter was lower case then the author changed it to uppercase.

Some plugin authors updated their libraries and others didn't. In the meantime the original library author reverted the case change.

Now I find myself in a state where my application won't build due to to case import collisions.

How can one go about fixing this?

Many thanks

  • 写回答

1条回答 默认 最新

  • dqba94394 2017-04-25 19:18
    关注

    You could vendor the dependencies, and then go into the vendor/ directory and manually change (try greping or seding the dependency), the dependencies.

    For an introduction to vendoring, try here, https://blog.gopheracademy.com/advent-2015/vendor-folder/

    The original repo can still live in your GOPATH, but the 'corrected' version can go in the vendor folder, in which the compiler will look first when linking dependencies.

    There are many tools for vendoring, I use govendor

    Edit

    As mkopriva mentions in the comments, you can refactor import names using the gofmt tool:

    gofmt -w -r '"path/to/PackageName" -> "path/to/packagename"' ./

    gofmt -w -r 'PackageName.x -> packagename.x' ./

    The lowercase single character identifier is a wildcard.

    from the docs

    The rewrite rule specified with the -r flag must be a string of the form:

    pattern -> replacement

    Both pattern and replacement must be valid Go expressions. In the pattern, single-character lowercase identifiers serve as wildcards matching arbitrary sub-expressions; those expressions will be substituted for the same identifiers in the replacement.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度