Go实战--golang中使用go-spew(davecgh/go-spew)
来源:互联网 发布:锐捷网络校招 编辑:程序博客网 时间:2024/03/29 02:49
生命不止,继续 go go go !!!
花絮:
一系列的事儿,开始想想未来如何,要不要离开北京。利用周末,去了趟南京,感觉很好。
我的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.Dump
package mainimport ( "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 mainimport ( "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: <**>5circular: {1 <*>{1 <*><shown>}}
spew.ConfigState
package mainimport ( "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中使用go-spew(davecgh/go-spew)
- Go实战--golang中使用MongoDB(mgo)
- Go实战--go中使用libphonenumber(The way to go)
- Go实战--go中使用cookie(The way to go)
- Go实战--go中使用rpc(The way to go)
- Go实战--golang中使用JWT(JSON Web Token)
- Go实战--golang中使用markdown(russross/blackfriday)
- Go实战--golang中使用firebase实时数据库(zabawaba99/firego)
- Go实战--golang中使用RethinkDB(gorethink/gorethink.v3)
- Go实战--golang中使用redis(redigo和go-redis/redis)
- Go实战--golang中使用WebSocket实时聊天室(gorilla/websocket、nkovacs/go-socket.io)
- Go实战--golang中使用echo和MySQL搭建api(labstack/echo、go-sql-driver/mysql)
- Go实战--golang中使用echo嵌入静态资源(labstack/echo、GeertJohan/go.rice)
- Go实战--golang中使用号称全世界最快的JSON解析器json-iterator(json-iterator/go)
- Go实战--golang中读写文件的几种方式
- Go实战--golang中读写文件的几种方式
- Go实战--go中编码转换(The way to go)
- Go实战--golang使用ssl连接MongoDB(mgo)
- 内网穿透二
- 解决 perl: warning: Setting locale failed.
- 查看电脑端口以及关闭电脑端口
- LeetCode初体验
- 在线报表设计实战系列 – ②制作表格类报表
- Go实战--golang中使用go-spew(davecgh/go-spew)
- 学习记录--nio(二)
- SEGGER推出超强劲,免费的实时性测试软件SystemView
- 继承(1)
- (笔记)RecyclerView item按下变色效果 没有生效
- 【个人笔记】mysql重安
- 使用maven创建web项目
- iOS 宏(define)与常量(const)的正确使用
- javax的NotBlank和Email注解失效