Is it possible to build-constraint a Go module?

I am using https://github.com/shirou/gopsutil 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?

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.

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

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