Go的文件名约定是什么? [英] What are conventions for filenames in Go?

查看:128
本文介绍了Go的文件名约定是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这个约定是否也适用于文件名?

我可以在Go中找到命名包的约定:单词之间没有下划线,

您是否也将一个结构放在一个文件中,就好像您为java类所做的一样,然后在结构后命名该文件?



<目前,如果我有一个struct WebServer,我把它放在一个文件web_server.go中。

有几条指导原则跟随。


  1. 以。开头的文件名。或_被转换工具忽略
  2. 带有后缀 _test.go 的文件仅被编译并由 go test 工具。

  3. 具有os和体系结构特定后缀的文件自动遵循相同的约束,例如 name_linux.go 只会建立在linux上, name_amd64.go 只会建立在amd64上。这与在文件顶部有一个 // + build amd64


$ b是一样的$ b

有关更多详细信息,请参阅 go build 工具的文档: https://golang.org/pkg/go/build/


I could find the conventions for naming packages in Go: no underscore between words, everything lowercase.

Does this convention apply to the filenames too?

Do you also put one struct in one file as if you did for a java class and then name the file after the struct?

Currently, if I have a struct WebServer, I put it in a file web_server.go.

解决方案

There's a few guidelines to follow.

  1. File names that begin with "." or "_" are ignored by the go tool
  2. Files with the suffix _test.go are only compiled and run by the go test tool.
  3. Files with os and architecture specific suffixes automatically follow those same constraints, e.g. name_linux.go will only build on linux, name_amd64.go will only build on amd64. This is the same as having a //+build amd64 line at the top of the file

See the docs for the go build tool for more details: https://golang.org/pkg/go/build/

这篇关于Go的文件名约定是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆