如何打印反斜杠?

How to print backslash in go?

我有以下代码片段:

const byte1 = 0x19;
const byte2 = 0x45;
msg := fmt.Sprintf("\x%x\x%x message", byte1, byte2)
log.Info("Learning go fmt", "msg", msg)

我明白了:

msg="\x19\x45 message"

为什么反斜杠重复?根据此 website,格式内的 \ 应产生 \.

@nilsocket 的评论是正确的。问题是我使用的是 Ethereum log 包。它取消了字符串。如果我这样做:

fmt.Println("\x%x\x%x message", byte1, byte2)

它工作得很好。