构建标签

// +build linux

package lib

var OnlyAccessibleInLinux int // Will only be compiled in Linux

通过在其前面放置 ! 来取消平台:

// +build !windows

package lib

var NotWindows int // Will be compiled in all platforms but not Windows

可以通过用空格分隔来指定平台列表

// +build linux darwin plan9

package lib

var SomeUnix int // Will be compiled in linux, darwin and plan9 but not on others