Go fmt on a whole source tree
You can use three dots (...
) as a wildcard. So for example, the following command will format all github.com packages:
go fmt github.com/...
This wildcard also works with other go commands like go list
, go get
and so. There is no need to remember such an ugly find command.
If you use gofmt
instead of go fmt
, it's recursive. For example, following command
gofmt -s -w .
(notice the little dot at end) recursively formats, simplifies, and saves result into every file under current directory. I have a shell alias gf
defined as gofmt -s -w .
and find it quite handy.
Try gofmt -l .
(list files whose formatting differs from gofmt's) first if you want :-)
Also, you can try to run command:
go fmt ./...
from your project directory.