HiveBrain v1.2.0
Get Started
← Back to all entries
patterngoCritical

What are conventions for filenames in Go?

Submitted by: @import:stackoverflow-api··
0
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.

Solution

There's a few guidelines to follow.

  • File names that begin with "." or "_" are ignored by the go tool



  • Files with the suffix _test.go are only compiled and run by the go test tool.



  • 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 go docs for more details: https://pkg.go.dev/cmd/go

Context

Stack Overflow Q#25161774, score: 220

Revisions (0)

No revisions yet.