本文介绍了如何摆脱Println中的兽医警告%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码
package main
import (
"fmt"
)
func main() {
fmt.Println("%%dude")
}
游乐场链接: https://play.golang.org/p/Shq5pMHg4bj
给出兽医
警告
./prog.go:8:2: Println call has possible formatting directive %d
我怎么能告诉兽医我真的想写两个百分号而不要警告我?
How can I tell go vet that I really want to write two percent signs and not to warn me?
推荐答案
您不能真正禁止这样做,但是即使您可以使用自定义规则和标志,我也不会这样做,因为其他人仍会构建您的代码碰到这个.
You can't really supress that, but even if you could with custom rules and flags, I wouldn't do it because someone else building your code will still run into this.
相反,您可以使用这些产生相同输出的替代方法中的任何一种,而无需 vet
发出任何警告:
Instead you may use any of these alternatives which produce the same output without any warnings from vet
:
fmt.Println("%%"+"dude")
fmt.Println("%\x25dude")
fmt.Printf("%%%%dude\n")
s := "%%dude"
fmt.Println(s)
在转到游乐场上尝试示例.
这篇关于如何摆脱Println中的兽医警告%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!