patterngoCritical
What are conventions for filenames in Go?
Viewed 0 times
areforfilenameswhatconventions
Problem
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.
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.
Solution
There's a few guidelines to follow.
See the
- File names that begin with "." or "_" are ignored by the go tool
- Files with the suffix
_test.goare only compiled and run by thego testtool.
- Files with os and architecture specific suffixes automatically follow those same constraints, e.g.
name_linux.gowill only build on linux,name_amd64.gowill only build on amd64. This is the same as having a//+build amd64line at the top of the file
See the
go docs for more details: https://pkg.go.dev/cmd/goContext
Stack Overflow Q#25161774, score: 220
Revisions (0)
No revisions yet.