How can I handle platform modules in Go?

I am writing a command line utility in Go so that (as part of its work) I need to get the password from the user. There is a great gopass module for Unix there, and I know how to write it for the Windows console. The problem is that the Windows module will obviously not be built on * nix, and the * nix version will not be built on Windows. Since Go does not have support in the preprocessor (as far as I can tell), I absolutely do not know how to approach this correctly. I know this is possible, since Go itself should do this for its own libraries, but the tool I'm used to (conditional import / preprocessors / etc.) Seems to be missing.

+4
source share
1 answer

Go has build restrictions that can be specified as comments in a .go file or as part of a file name.

One set of restrictions for the target operating system, so you can have one file for Windows, one of which, for example, Linux, and implement the same function in two different ways in two.

For more information on build restrictions, see http://golang.org/pkg/go/build/#hdr-Build_Constraints

+8
source

Source: https://habr.com/ru/post/1482598/


All Articles