我看到既有gofmt也有go fmt。gofmt和go fmt有什么区别?
发布于 2019-03-24 08:08:51
运行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发布于 2019-03-24 07:58:54
gofmt命令将处理作为参数给定的文件。go fmt工具在作为参数给出的包路径中的所有文件上运行gofmt。因此,如果我在encoding/gob目录中,
gofmt decode.go
在工具运行时,将格式化单个文件decode.go
去fmt。
(。实际上是默认的)将格式化编码/gob包中的所有文件。
https://stackoverflow.com/questions/55319495
复制相似问题