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.

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

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。