Hacker News new | ask | show | jobs
by quickthrower2 1468 days ago
Searching around a few blogs mention _linux.go files are only compiled on Linux. But I see nothing in the official documentation, will at least in my quick searches.

It will catch someone out who uses BSD as an acronym for something in their domain model (Bulk Sales Discount?) then xyz_bsd.go doesn't compile.

2 comments

https://pkg.go.dev/cmd/go#hdr-Build_constraints

  If a file's name, after stripping the extension and a possible _test suffix, matches any of the following patterns:

  *_GOOS
  *_GOARCH
  \*_GOOS_GOARCH
  (example: source_windows_amd64.go) where GOOS and GOARCH represent any known operating system and architecture values respectively, then the file is considered to have an implicit build constraint requiring those terms (in addition to any explicit constraints in the file).
Idiomatically in Go that file would be named `xyz-bsd.go`. All special filename behavior is triggered by `_suffix`.