https://github.com/motemen/go-ctxize
Rewrite functions to have "Context"s
https://github.com/motemen/go-ctxize
Last synced: 2 months ago
JSON representation
Rewrite functions to have "Context"s
- Host: GitHub
- URL: https://github.com/motemen/go-ctxize
- Owner: motemen
- Created: 2019-03-12T00:57:00.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-25T13:08:28.000Z (about 6 years ago)
- Last Synced: 2025-03-26T18:43:42.679Z (3 months ago)
- Language: Go
- Size: 36.1 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-ctxize
Sometimes it's hard to touch every source files to modify functions to context-aware, adding `ctx` to each callers.
goctxize rewrites Go source files to add `ctx context.Context` as a first argument of specified function,
with callers of the function rewritten so.goctxize [-var ] [.]. [...]
For example:
// $GOPATH/src/example.com/foo/foo.go
package foofunc F() {
}// $GOPATH/src/example.com/foo/foo_test.go
package fooimport "testing"
func TestF(t *testing.T) {
F()
}// $GOPATH/src/example.com/bar/bar.go
package barimport (
"example.com/foo"
)func bar() {
foo.F()
}Given source above, `goctxize example.com/foo.F` produces below:
// $GOPATH/src/example.com/foo/foo.go
package fooimport "context"
func F(ctx context.Context) {
}// $GOPATH/src/example.com/foo/foo_test.go
package fooimport (
"context"
"testing"
)func TestF(t *testing.T) {
ctx := context.TODO()F(ctx)
}While executing `goctxize example.com/foo.F example.com/bar` rewrites package bar too:
// $GOPATH/src/example.com/bar/bar.go
package barimport (
"context"
"example.com/foo"
)func bar() {
ctx := context.TODO()foo.F(ctx)
}