您正在打印切片的值。它被格式化/印刷print.go
,未导出的函数printReflectValue()
,目前线#980:
855 func (p *pp) printReflectValue(value reflect.Value, verb rune, depth int)
(wasString bool) {
// ...
947 case reflect.Array, reflect.Slice:
// ...
979 } else {
980 p.buf.WriteByte('[')
981 }
和线#995:
994 } else {
995 p.buf.WriteByte(']')
996 }
请注意,这是为 “一般” 的切片(如您的[]string
) ,字节切片不同的处理:
948 // Byte slices are special:
949 // - Handle []byte (== []uint8) with fmtBytes.
950 // - Handle []T, where T is a named byte type, with fmtBytes only
[]byte
被印刷在未导出函数fmtBytes()
:
533 func (p *pp) fmtBytes(v []byte, verb rune, typ reflect.Type, depth int) {
// ...
551 } else {
552 p.buf.WriteByte('[')
553 }
// ...
566 } else {
567 p.buf.WriteByte(']')
568 }
非常感谢您的快速指出! – Bob