golang 中是否還存在類似 C/C 的宏,以便在除錯階段,允許開發人員列印一些額外的除錯資訊?而在正式版中,只需將這些宏設定為false,這樣它們就不會被編譯,也不會列印額外的資訊。這是一個片段來說明我的意思。
func demo() {
// ...
// the following line will not be compiled in release only in debug phase
printMyDebugInfo(variable)
// ...
}
uj5u.com熱心網友回復:
最接近的可能是在兩個版本中定義除錯列印功能。
一種用于除錯模式:
//go:build debug
package whatever
func debugPrint(in string) {
print(in)
}
一種用于生產:
//go:build !debug
package whatever
func debugPrint(in string) {}
然后go build -tags debug在您想使用除錯版本時使用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/443017.html
標籤:走
