gpt4 book ai didi

go - gofmt 和 go fmt 有什么区别?

转载 作者:IT王子 更新时间:2023-10-29 02:26:53 44 4
gpt4 key购买 nike

我看到有 gofmtgo fmt。 gofmt 和 go fmt 有什么区别?

最佳答案

运行 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

关于go - gofmt 和 go fmt 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55319495/

44 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com