打印时如何取消对字段的引用?

打印时如何取消对字段的引用?,第1张

打印时如何取消对字段的引用?

有一个很棒软件包,称为go-spew。正是您想要的。

package mainimport (  "github.com/davecgh/go-spew/spew")type (  SomeStruct struct {    Field1 string    Field2 int    Field3 *somePointer  }  somePointer struct {    field string  })func main() {  s := SomeStruct{    Field1: "Yahoo",    Field2: 500,    Field3: &somePointer{"I want to see what is in here"},  }  spew.Dump(s)}

将为您提供以下输出:

(main.SomeStruct) { Field1: (string) "Yahoo", Field2: (int) 500, Field3: (*main.somePointer)(0x2102a7230)({  field: (string) "I want to see what is in here" })}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5028625.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存