如何批量更改GO软件包的别名? [英] How to change GO package alias en masse?
问题描述
我想重命名许多文件中的许多软件包.同时,我还想更改软件包别名.有什么工具可以做到这一点吗?我在go/x/tools中找到的那些只能更改软件包的导入.
I want rename many packages across many files. At the same time, I also want to change package aliases. Is there any tool to do that? The ones I find in go/x/tools only change package imports.
我想从导入"github.com/a/b"
I want to go from import "github.com/a/b"
到
导入b"github.com/c/d"
import b "github.com/c/d"
推荐答案
std工具有一个很酷的技巧.
There is a cool trick with std tools.
gofmt
具有一个 -r规则
选项,其工作方式如下:
gofmt
has an option -r rule
which works like this:
gofmt -w -l -r"github.com/a/b-> github.com/c/d".
其中规则
的格式为 pattern->替换
请参见 gofmt文档
还有一个 gofix
工具,但我还没有尝试过,请参见 docs 和博客
Also there is a gofix
tool, but I haven't tried it, see docs and blog
这篇关于如何批量更改GO软件包的别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!