英文:
Is it possible in Go to use ldflags to set an unassigned integer?
问题
我知道有几种方法可以通过添加一点额外的代码来完成这个任务,但这让我很好奇...是否有一种方法可以使用ldflags在Go应用程序中设置一个未分配的整数?例如,你可以调用...
go build -ldflags "-X main.CurrentEnvironment 1"
然后它会设置为:
package main
var CurrentEnvironment int
func main() {
...
}
我没有找到任何支持这一点的文档,所以我认为答案是否定的,但也许有一种方法。
英文:
I know there are several ways of accomplishing this with just a little extra code, but it got me curious... Is there a way to set an unassigned integer in a Go application using ldflags? For instance, could you call...
go build -ldflags "-X main.CurrentEnvironment 1"
And have it set:
package main
var CurrentEnvironment int
func main() {
...
}
I couldn't find any documentation supporting this so I presume the answer is no but maybe there's a way.
答案1
得分: 5
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论