Go实战--golang中使用go-spew(davecgh/go-spew)
2017-11-30 11:31
495 查看
生命不止,继续 go go go !!!
花絮:
一系列的事儿,开始想想未来如何,要不要离开北京。利用周末,去了趟南京,感觉很好。
我的csdn博客uv访问量如下:
—————————————————-悲伤的分割线————————————————–
今天跟大家一起分享一个golang的第三方库go-spew。
简介:
Go-spew implements a deep pretty printer for Go data structures to aid in debugging. A comprehensive suite of tests with 100% test coverage is provided to ensure proper functionality. See test_coverage.txt for the gocov coverage report. Go-spew is licensed under the liberal ISC license, so it may be used in open source or commercial projects.
github地址:
https://github.com/davecgh/go-spew
Star: 1688
文档地址:
https://godoc.org/github.com/davecgh/go-spew/spew
获取:
go get -u github.com/davecgh/go-spew/spew
dump a variable:
输出:
spew.Printf
输出:
spew.ConfigState
输出:
花絮:
一系列的事儿,开始想想未来如何,要不要离开北京。利用周末,去了趟南京,感觉很好。
我的csdn博客uv访问量如下:
—————————————————-悲伤的分割线————————————————–
今天跟大家一起分享一个golang的第三方库go-spew。
go-spew
Implements a deep pretty printer for Go data structures to aid in debugging简介:
Go-spew implements a deep pretty printer for Go data structures to aid in debugging. A comprehensive suite of tests with 100% test coverage is provided to ensure proper functionality. See test_coverage.txt for the gocov coverage report. Go-spew is licensed under the liberal ISC license, so it may be used in open source or commercial projects.
github地址:
https://github.com/davecgh/go-spew
Star: 1688
文档地址:
https://godoc.org/github.com/davecgh/go-spew/spew
获取:
go get -u github.com/davecgh/go-spew/spew
dump a variable:
spew.Dump(myVar1, myVar2, ...) spew.Fdump(someWriter, myVar1, myVar2, ...) str := spew.Sdump(myVar1, myVar2, ...)
应用
spew.Dumppackage main import ( "github.com/davecgh/go-spew/spew" ) type Project struct { Id int64 `json:"project_id"` Title string `json:"title"` Name string `json:"name"` Data string `json:"data"` Commits string `json:"commits"` } func main() { o := Project{Name: "hello", Title: "world"} spew.Dump(o) }
输出:
(main.Project) { Id: (int64) 0, Title: (string) (len=5) "world", Name: (string) (len=5) "hello", Data: (string) "", Commits: (string) "" }
spew.Printf
package main import ( "github.com/davecgh/go-spew/spew" ) func main() { ui8 := uint8(5) pui8 := &ui8 ppui8 := &pui8 // Create a circular data type. type circular struct { ui8 uint8 c *circular } c := circular{ui8: 1} c.c = &c // Print! spew.Printf("ppui8: %v\n", ppui8) spew.Printf("circular: %v\n", c) }
输出:
ppui8: <**>5 circular: {1 <*>{1 <*><shown>}}
spew.ConfigState
package main import ( "github.com/davecgh/go-spew/spew" ) func main() { scs := spew.ConfigState{Indent: "\t"} // Output using the ConfigState instance. v := map[string]int{"one": 1} scs.Printf("v: %v\n", v) scs.Dump(v) }
输出:
v: map[one:1] (map[string]int) (len=1) { (string) (len=3) "one": (int) 1 }
相关文章推荐
- Go实战--golang中使用WebSocket实时聊天室(gorilla/websocket、nkovacs/go-socket.io)
- golang实战使用gin+xorm搭建go语言web框架restgo详解5.4 控制器参数绑定
- Go实战--golang中使用JWT(JSON Web Token)
- golang实战使用gin+xorm搭建go语言web框架restgo详解5.5 控制器模型绑定
- java程序员10分钟可上手的golang框架golang实战使用gin+xorm搭建go语言web框架restgo
- Go实战--golang中使用echo和MySQL搭建api(labstack/echo、go-sql-driver/mysql)
- Go实战--golang使用ssl连接MongoDB(mgo)
- golang实战使用gin+xorm搭建go语言web框架restgo详解5.6 控制器参数校验
- Go实战--golang中使用gRPC和Protobuf实现高性能api(golang/protobuf、google.golang.org/grpc)
- Go实战--使用golang开发Windows Gui桌面程序(lxn/walk)
- golang实战使用gin+xorm搭建go语言web框架restgo详解5.7 控制器数据响应
- Go实战--golang中使用图片和验证码(dchest/captcha)
- golang实战使用gin+xorm搭建go语言web框架restgo详解5.9 控制器controller编程示例
- golang实战使用gin+xorm搭建go语言web框架restgo详解6.1 模型M和Orm
- golang实战使用gin+xorm搭建go语言web框架restgo详解1.1 go语言的困境
- golang实战使用gin+xorm搭建go语言web框架restgo详解6.4 推荐编程方式
- Go实战--golang中使用echo框架中JSONP(labstack/echo)
- Go实战--golang中使用redis(redigo和go-redis/redis)
- Go实战--golang中OAuth2.0的使用(使用google账号进行登陆验证)
- golang实战使用gin+xorm搭建go语言web框架restgo详解1.2 我要做什么