最初から完璧な設計と実装ができているなら苦労はないわけだけど、実際にはそうもいかない。具体的にはある程度の規模になってくると「あーこの関数 context.Context 対応したい!」みたいな気持ちが湧いてくるわけです。context 対応ってのは、第一引数に ctx context.Context を追加することですね。 そういうことをやるツールを書きました。 GitHub - motemen/go-ctxize: Rewrite functions to have "Context"s go get github.com/motemen/go-ctxize/cmd/goctxize で、goctxize というバイナリが手に入ります。 サンプル README やテストにある例だけど、 // $GOPATH/src/example.com/foo/foo.go package foo