Move and rename Go declarations across files and packages.
Gorelo loads all Go packages in the current module (respecting all build constraints simultaneously), applies the requested moves and renames, and rewrites every file that references the affected declarations.
go install github.com/loov/gorelo@latest
gorelo [flags]
| Flag | Default | Description |
|---|---|---|
-f |
gorelo.rules |
Path to a rules file |
-r |
(repeatable) | Inline rule, same syntax as a rules file line |
-dry |
false |
Print plan without applying changes |
-v |
false |
Print each file edit to stderr |
-stubs |
false |
Generate //go:fix inline backward-compat stubs |
Rules can come from a file (-f) and/or inline (-r). Both are merged.
gorelo # apply gorelo.rules
gorelo -f refactor.rules # different rules file
gorelo -r "Server -> server.go" # inline rule
gorelo -r "server.go <- Server Client" -v # reverse notation, verbose
gorelo -dry -f gorelo.rules # preview without writingSee EXAMPLE.md for a walkthrough of splitting a flat package
into subpackages (server/, db/, service/) with private-to-public renames.
Forward notation is compact and works well for inline -r flags:
Server ServerOption -> server.go
Reverse notation reads better in rules files since grouping by destination is the common case:
server.go <- Server ServerOption
Multiline reverse block (indented continuation):
server.go <-
Server
ServerOption
Config
Rename a declaration at the destination with =:
OldName=NewName -> target.go
Rename a struct field with #:
ServerOptions#Listen=Address
Rename a nested anonymous struct field with a dotted path:
ServerOptions#Limits.Min=MinValue
Disambiguate by source file:
server_linux.go:Server -> server/core_linux.go
By relative or full package path (last . after last / separates
package from name):
./util.Helper -> helpers.go
github.com/loov/gorelo.Server -> server.go
Directives start with @ and configure processing behavior:
@fmt goimports # run formatter on modified files
@stubs=true # generate //go:fix backward-compat stubs
Gorelo uses a multi-AST approach: it discovers all .go files (including
test files and platform-specific variants like _linux.go, _windows.go)
and type-checks each build-constraint group. This lets it track identifiers
across all platforms in a single run.
The compilation pipeline:
- Parse rules into relocation instructions
- Load and type-check all packages (
mast.Load) - Resolve declarations and synthesize related moves (e.g. methods follow their type)
- Compute source/target spans respecting block semantics (
const,var,importgroups) - Check build-constraint compatibility and detect conflicts
- Compute rename and import edits
- Rewrite consumer files that reference moved/renamed declarations
- Assemble and apply file edits
A companion web UI for browsing Go packages with identifier rename-group highlighting.
go install github.com/loov/gorelo/cmd/mast-browser@latest
mast-browser -dir . -listen 127.0.0.1:8080
Click any identifier to highlight all references in the same rename group.
See CONTRIBUTING.md.