Golang在go版本1.14上使用多行构建标签。

huangapple go评论75阅读模式
英文:

Golang build tags on multiple lines with go version 1.14

问题

我正在测试套件中使用多个Golang构建标签。

在Go 1.14中,有没有办法将它们拆分成多行?

例如,我想将这一行拆分成多行:

// +build integration integration_auth_pwd integration_auth_tls integration_config integration_groups integration_groups_mongodb integration_groups_sql integration_groups_cassandra

我尝试将它们拆分成这样:

// +build integration integration_auth_pwd integration_auth_tls \
//integration_config integration_groups integration_groups_mongodb \
//integration_groups_sql integration_groups_cassandra

但这样做没有起作用。

英文:

I am using multiple Golang build tags in a test suite.

Is there a way to split them into multiple lines in go 1.14?

For instance I want to split this line into multiple lines:

// +build integration integration_auth_pwd integration_auth_tls integration_config integration_groups integration_groups_mongodb integration_groups_sql integration_groups_cassandra

I have tried to split them like this:

// +build integration integration_auth_pwd integration_auth_tls \
//integration_config integration_groups integration_groups_mongodb \
//integration_groups_sql integration_groups_cassandra

This didn't work.

答案1

得分: 2

你不能打破// +build的约束条件。

你可以指定多个// +build行。但要知道,一行中用空格分隔的约束条件是逻辑与关系,而多行中的约束条件是逻辑或关系,所以它们是不同的。

你不能将要求分成多行,要使用单行。

友情提示:Go 1.14不再受支持。请使用最新的Go版本。无论在Go 1.14中发现了什么安全漏洞,你将在余生中都会受到其影响。

英文:

You can't break // +build constraints.

You may specify multiple // +build lines. But know that space separated constraints in a line are ANDed together, and constraints specified in multiple lines are ORed together, so it's not the same.

You can't break your requirement into multiple lines, use a single line.

A friendly note: Go 1.14 isn't supported anymore. Please do use the latest Go. Whatever security vulnerabilities are discovered in Go 1.14, you'll be vulnerable to those for the rest of your life.

huangapple
  • 本文由 发表于 2021年10月29日 20:03:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/69768554.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定