gofmt と go fmt の違いは何ですか? 質問する

gofmt と go fmt の違いは何ですか? 質問する

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

おすすめ記事