I'm learning Go but I can't find this answer anywhere. Is there any official standard for file extensions in web development? I've seen multiple conventions like .tmpl
and .gtpl
, which is what? Thanks.
是Web开发中文件扩展名的标准吗?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- dongsong4418 2018-02-07 09:40关注
There's no fixed standard, but there are some fairly common practices. For templates on web projects, I use the extension appropriate for the type of file it is, e.g.
.html
,.css
, etc. That's what's done in the widely-read-and-cited Writing Web Applications blog post on the official Go blog, which makes it fairly standard. I find it useful for easy syntax highlighting without changing my editor's settings/config, and processing by other tools. I put these templates in a/templates/
directory to keep them separate from non-template files.I've seen and used
.tmpl
before, it's in official docs for both html and text template packages, which makes that fairly standard too, and I think it makes sense if you're making a file-type-agnostic template, or you don't have any associations that are useful by more specialized file type.For Go code files, I always use the
.go
extension, which works well with the Go toolset. It's what you generally see in official Go documentation, such as this introductory document on How to Write Go Code. For executables, I don't append any file extension. The default result when yougo build <name>.go
is an executable called<name>
, and so that makes it a common practice.本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报