英文:
How to format a multiline string literal
问题
我正在尝试将一个字符串文字分成多行,以满足我的代码检查工具对短行的期望。以下是当前的代码,它通过了代码检查:
return nil,
"",
errors.Errorf(
"nil cursor returned when querying for transactions for block hash %s, "+
"page token %s and limit %d",
blockHash,
pageToken,
limit,
)
我不喜欢字符串文字的格式。它在美学上感觉不对;)。有没有更好的格式化方式?谢谢!
英文:
I am trying to break a string literal into multiple lines to meet my linter's expectations of short lines. Following is the code right now, it passes the linter check:
return nil,
"",
errors.Errorf(
`nil cursor returned when querying for transactions for block hash %s,
page token %s and limit %d`,
blockHash,
pageToken,
limit,
)
I don't like the formatting of the string literal. It feels aesthetically wrong ;). Is there a better way to format this? Thanks!
答案1
得分: 1
使用字符串拼接来构建较短行的字符串:
errors.Errorf(
`在查询交易时返回了空游标` +
`,区块哈希为 %s,页面令牌为 %s,限制为 %d`,
blockHash,
pageToken,
limit,
)
英文:
Use string concatenation to construct the string from shorter lines:
errors.Errorf(
`nil cursor returned when querying for transactions` +
` for block hash %s, page token %s and limit %d`,
blockHash,
pageToken,
limit,
)
答案2
得分: 1
你可以使用字符串拼接:
errors.Errorf(`在查询块哈希为%s、页面令牌为%s和限制为%d的交易时返回了空游标`,
blockHash,
pageToken,
limit,
)
英文:
You can use string addition:
errors.Errorf(`nil cursor returned when querying for `+
`transactions for block hash %s, page token %s and limit %d`,
blockHash,
pageToken,
limit,
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论