Loading...
Loading...
Golang refactoring — the safe, at-scale process for restructuring existing Go code: a coverage-adaptive safety net, tool-driven behavior-preserving transforms (gopls Rename/Inline/Extract, `gofmt -r`, `eg`, `gopatch`, `go/analysis` fixers), the Fowler catalog mapped to Go, breaking import cycles, moving types across packages, and a human-in-the-loop workflow of small stacked PRs on a refactoring branch. Apply when code is hard to maintain, a function/type has grown too large, a code smell needs fixing, adding a feature is blocked by the current structure, or the user asks to clean up, refactor, or improve Go code — also for renaming at scale, extracting functions/interfaces, moving code between packages, splitting packages, or planning a multi-step refactor. Target styles owned elsewhere → See `samber/cc-skills-golang@golang-naming` (renames), `@golang-project-layout` (splits), `@golang-modernize` (idioms), `@golang-code-style` (control flow), `@golang-design-patterns` (patterns/DI).
npx skill4agent add samber/cc-skills-golang golang-refactoringCommunity default. A company skill that explicitly supersedesskill takes precedence.samber/cc-skills-golang@golang-refactoring
ultrathinkultracodegofmt -regmodernizeultracodegoplsgo install golang.org/x/tools/gopls@latestgolangci-lintbenchstatdeadcodeeggopatchsamber/cc-skills-golang@golang-goplstext/templatego build ./... && go vet ./... && go test ./...-racebenchstat-benchvargofmt -reggopatchgo/analysistype A = Btext/templatereflectjsondbsamber/cc-skills-golang@golang-securitygolang-safetygo test| Risk | Transforms | Safety requirement |
|---|---|---|
| Low | gopls Rename, Extract Variable/Constant, Inline Variable, | Build/vet/test after the step is enough |
| Medium | Extract Function/Method (Extract is best-effort — verify comments/behavior survived), Inline Call across packages, single-parameter add/remove, introducing generics | Add or confirm targeted tests over the blast radius first |
| High | Change signature across many callers, moving types/functions across packages, splitting/merging packages, breaking import cycles, exported-API or major-version changes | Full safety net + human checkpoint before landing |
go vet ./...golangci-lint rungo test -race ./...benchstat old.txt new.txt~go tool cover -func-coverpkg=./...refactor/<topic>// REFACTOR(step N): ...ultracodegofmt -reggopatchgo/analysis//go:fix inlinedave/dstsamber/cc-skills-golang@golang-namingsamber/cc-skills-golang@golang-project-layoutsamber/cc-skills-golang@golang-modernizeinterface{}anyslicesmapssamber/cc-skills-golang@golang-code-stylesamber/cc-skills-golang@golang-design-patternssamber/cc-skills-golang@golang-testingsamber/cc-skills-golang@golang-lintgolangci-lintsamber/cc-skills-golang@golang-securitygolang-safetygopls