【参考】https://ask.csdn.net/questions/1010153
问:Go有没有类似C语言的编译开关
#ifdef COMPILE_OPTION
{编译此代码...}
#elif
答:有,Go有一个叫作构建约束的功能
main.go
package main
func main() {
println("main()")
conditionalFunction()
}
a.go
// +build COMPILE_OPTION
package main
func conditionalFunction() {
println("conditionalFunction")
}
b.go
// +build !COMPILE_OPTION
package main
func conditionalFunction() {
}
输出
% go build -o example ; ./example
main()
% go build -o example -tags COMPILE_OPTION; ./example
main()
conditionalFunction
网友评论