gofmt
と の両方があることがわかりましたgo fmt
。gofmt と go fmt の違いは何ですか?
ベストアンサー1
実行しgo help fmt
て違いを確認します。簡単に言うと、引数で指定されたパッケージでgo fmt
実行されます。gofmt -l -w
この-w
フラグは結果をソース ファイルに書き戻します。この-l
フラグは変更されたファイルの名前を出力します。
の引数はgo fmt
パッケージです (go help packages
説明を表示するには実行してください)。 の引数はgofmt
ファイル システム パスです。
引数がどのように異なって処理されるかを示す例をいくつか示します。
gofmt -w . # formats files in current directory and all sub-directories
go fmt ./... # similar to previous
go fmt . # formats files in current package
gofmt -w foo/bar # formats files in directory $PWD/foo/bar and sub-dirs
go fmt foo/bar # formats files in directory $GOPATH/src/foo/bar
gofmt -w # error, no file or directory specified
go fmt # formats files in current package