swt*_*rgn 3 compilation build go
我在头文件中有两个具有不同构建约束的go文件.
constants_production.go:
// +build production,!staging
package main
const (
URL = "production"
)
Run Code Online (Sandbox Code Playgroud)
constants_staging.go:
// +build staging,!production
package main
const (
URL = "staging"
)
Run Code Online (Sandbox Code Playgroud)
main.go:
package main
func main() {
fmt.Println(URL)
}
Run Code Online (Sandbox Code Playgroud)
当我做的时候go install -tags "staging",有时会打印production; 有时,它打印staging.同样,当我这样做的时候go install -tags "production"......
如何在每次构建时获得一致的输出?当我将staging指定为构建标志时,如何使其进行打印分段?当我将生产指定为构建标志时,如何使其打印生产?我在这里做错了吗?
go buildgo install如果看起来没有任何变化,它将不会重建包(二进制) - 并且它对命令行构建标记的更改不敏感.
一种方法是-v在构建时添加打印包:
$ go install -v -tags "staging"
my/server
$ go install -v -tags "production"
(no output)
Run Code Online (Sandbox Code Playgroud)
您可以通过添加-a标志强制重建,这往往是过度的:
$ go install -a -v -tags "production"
my/server
Run Code Online (Sandbox Code Playgroud)
...或者在构建之前触摸服务器源文件:
$ touch main.go
$ go install -a -tags "staging"
Run Code Online (Sandbox Code Playgroud)
...或者在构建之前手动删除二进制文件:
$ rm .../bin/server
$ go install -a -tags "production"
Run Code Online (Sandbox Code Playgroud)