Is it possible to build-constraint a Go module?

(MMulthaupt) #1

I am using to retrieve stats about running processes, specifically cpu_times. This works fine for Linux and Windows, but is not implemented for Mac. If I were to write the Mac implementation in a package of my own, and keep using the module for Linux and Windows, could I build-constraint it so that it won’t be available for the Mac build? Is that even a good idea? Could it spare the linter or language server, or even affect the generated binary?

(Johan Dahl) #2

Hi. You would maybe have to write two files one which calls the packages functions and one which calls Mac os x specific calls. And use the build flags to include and exclude Darwin in the two files.

(Subbu Subbu) #3

Yes definitely you can, use build tags provided by golang.

(system) closed #4

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.