golang 更友好的格式化输出
发布时间:2020-12-16 19:12:09 所属栏目:大数据 来源:网络整理
导读:源码地址 安装 # 稳定版本go get -u -v gopkg.in/ffmt.v1# 最新版本go get -u -v github.com/go-ffmt/ffmt 用法 API 文档 示例 package mainimport ( ffmt "gopkg.in/ffmt.v1")func main() { example()}func example() { m := struct { String string Int in
安装# 稳定版本 go get -u -v gopkg.in/ffmt.v1 # 最新版本 go get -u -v github.com/go-ffmt/ffmt 用法API 文档 示例 package main import ( ffmt "gopkg.in/ffmt.v1" ) func main() { example() } func example() { m := struct { String string Int int Slice []int Map map[string]interface{} }{ "hello world",100,[]int{1,2,3,4,5,6},map[string]interface{}{ "A": 123,"BB": 456,},} fmt.Println(m) // fmt 默认输出 /* {hello world 100 [1 2 3 4 5 6] map[BB:456 A:123]} */ ffmt.Puts(m) // 较为友好的输出 /* { String: "hello world" Int: 100 Slice: [ 1 2 3 4 5 6 ] Map: { "A": 123 "BB": 456 } } */ ffmt.Print(m) // 同 Puts 但是字符串不加引号 /* { String: hello world Int: 100 Slice: [ 1 2 3 4 5 6 ] Map: { A: 123 BB: 456 } } */ ffmt.P(m) // 友好格式化加上类型 /* struct{ String: string(hello world) Int: int(100) Slice: slice[ int(1) int(2) int(3) int(4) int(5) int(6) ] Map: map{ string(A): int(123) string(BB): int(456) } } */ ffmt.Pjson(m) // 以 json 风格输出 /* { "Int": 100,"Map": { "A": 123,"BB": 456 },"Slice": [ 1,6 ],"String": "hello world" } */ m0 := ffmt.ToTable(m,m) // 按字段拆成表 ffmt.Puts(m0) /* [ [ "String" "Int" "Slice" "Map" ] [ "hello world" "100" "[1 2 3 4 5 6]" "map[A:123 BB:456]" ] ] */ m1 := ffmt.FmtTable(m0) // [][]string 表格式化 ffmt.Puts(m1) /* [ "String Int Slice Map " "hello world 100 [1 2 3 4 5 6] map[A:123 BB:456] " ] */ ffmt.Mark("hello") // 标记输出位置 /* main.go:122 hello */ } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- lua教程http://game.chinaitlab.com/program/30612.html
- 锁屏软件
- Jamie and Binary Sequence (changed after round) - CodeF
- NYoj 205 求余数[大数求余]
- lua函数精讲(一)
- hdu 1212 Big Number(对大数进行取余)
- Perl Project Improvement(2)Redis and Multi-Threads and
- delphi – 一个动态数组究竟是什么时候收集垃圾?
- java – Spring JdbcTemplate:如何限制选中的行?
- delphi – Anchors:= [akCenter]?