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.
I want to go from import "github.com/a/b"
to
import b "github.com/c/d"
There is a cool trick with std tools.
gofmt
has an option -r rule
which works like this:
gofmt -w -l -r "github.com/a/b -> github.com/c/d" .
where rule
have format pattern -> replacement
See gofmt docs
Also there is a gofix
tool, but I haven't tried it, see docs and blog