Tool to change import paths
-
Important case is to append suffix to existing path, i.e. to grow
gitlab.example.com/common/utils
intogitlab.example.com/common/utils/v2
use
go-imports-rename 'gitlab.example.com/common/utils/ ++'
to grow
gitlab.example.com/common/utils/package
intogitlab.example.com/common/utils/v2/package
-
Simple usage. Please do not use it for import paths upgrade from version below 2. Use
++
operator instead.go-imports-rename 'github.com/rsz/ => github.com/rs/'
will list all possible import path changes with given prefix
github.com/rsz/
in Go files in current directory and all its subdirectories. No saves will be done. -
Use
--save
flag to commit these changes:go-imports-rename --save 'github.com/rsz/ => github.com/rs/'
-
Use
--root
flag to diagnose or make changes in specific directory:go-imports-rename --root $GOPATH/src 'github.com/rsz/ => github.com/rs/'
Will diagnose changes in
$GOPATH/src
-
There is a shortcut for the fresh v1.x.y ⇒ v2.α.β migrations:
go-imports-rename 'github.com/user/project ++'
It is an equivalent for
go-imports-rename 'github.com/user/project/ => github.com/user/project/v2/'
In this case the utility takes care of paths and will not replace
github.com/user/projectNext
. Also,github.com/user/project/v2
won't change. You can also move fromv2
tov3
in the same waygo-imports-rename 'github.com/user/project/v2 ++'
-
You can jump through several migrations:
go-imports-rename 'github.com/user/project += 5'
It is an equivalent for
go-imports-rename 'github.com/user/project/ => github.com/user/project/v6'
-
Use
//
operator to imports rename with regular expressiongo-imports-rename '^gen/(.*)$ // gitlab.example.com/common/schema/$1'
will diagnose possible
gen/common
and similar imports changes intogitlab.example.com/common/schema/common
, etc