登录
首页 >  Golang >  Go问答

gofmt 和 go fmt 有什么区别?

来源:stackoverflow

时间:2024-04-03 17:03:34 245浏览 收藏

小伙伴们有没有觉得学习Golang很有意思?有意思就对了!今天就给大家带来《gofmt 和 go fmt 有什么区别?》,以下内容将会涉及到,若是在学习中对其中部分知识点有疑问,或许看了本文就能帮到你!

问题内容

我看到有 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

以上就是本文的全部内容了,是否有顺利帮助你解决问题?若是能给你带来学习上的帮助,请大家多多支持golang学习网!更多关于Golang的相关知识,也可关注golang学习网公众号。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>