This is a design draft for a tool (gomvfile) that would allow to migrate a set of symbols from a package to another.
- Isolate symbols that have to move: move all symbols to migrate into one or multiple separate source files. Those sources must not have depenencies on the internals (private symbols, private struct members) of the rest of the package.
- Use
gomvfile
to migrate the files to the target package
The task of the gomvfile tool (input: a set of files in a single package ($files
in package $src
), and a destination package $dst
):
- Collect the list of package block symbols in
$files
- exported =>
$symbols_pub
- private =>
$symbols_priv
- exported =>
- Check that $dst has no package block scoped symbol with name in (
$symbols_pub
,$symbols_priv
) - For each file in $src excluding
$files
:- check that none of
$symbols_priv
and private struct members defined in$files
are used
- check that none of
- Collect every source file in
$GOPATH
(excluding$files
) that:- imports one symbol of
$symbols_pub
from$src
=>$src_users
- imports
$dst
: warn if$dst
is imported as'.'
(or better, check that there will be no import conflict)
- imports one symbol of
- Move
$files
from$src
to$dst
- move files
- fix imports (remove imports of
$dst
, add imports of$src
)
- For files in
$src_users
:- determine the alias for importing
$dst
- if import of
$dst
exists, use the existing alias - add import of
$dst
if necessary
- replace symbols
$symbols_pub
- remove import of
$src
if none of its symbols are used anymore (maybe delagate this to goimports) - save
- determine the alias for importing
TODO:
- handle test sources among
$files
:- which are declared in package
$src
(maybe there is nothing special to do) - which are declared in another package (usually "${src}_test")
- which are declared in package
- update the proposal now that Go has type aliases which was not the case when the proposal has originally been designed