1

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"

codefx
  • 9,872
  • 16
  • 53
  • 81

1 Answers1

-1

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

Oleg Kovalov
  • 734
  • 11
  • 33
  • Thanks for sharing this cool trick! FWIW, I have written a python script to do basic search and replace. It does well enough to do the rest by hand. Here is my script: https://github.com/appscode/libbuild/blob/master/reimport.py – codefx Jun 16 '17 at 03:25