Skip to content

Commit c6d1f1b

Browse files
committed
readme
1 parent 48516e6 commit c6d1f1b

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

README.md

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# go-pprint
2+
一个能够格式化输出的golang小工具(pretty print)
3+
4+
为了方便开发和调试,能够清晰看到结构体的值:
5+
6+
```golang
7+
package main
8+
9+
import (
10+
"time"
11+
"github.com/timest/go-pprint"
12+
)
13+
14+
type Policy struct {
15+
Allow string
16+
Deny string
17+
}
18+
19+
type Host struct {
20+
ip string
21+
alias []string
22+
policy Policy
23+
}
24+
type Redis struct {
25+
name string // lower-case
26+
port uint // lower-case
27+
host Host
28+
}
29+
30+
type Web struct {
31+
Host string
32+
port int32 // lower-case
33+
Timeout time.Duration
34+
Rate float32
35+
Score []float32
36+
IP []string
37+
MySQL struct {
38+
Name string
39+
port int64 // lower-case
40+
}
41+
redis *Redis
42+
}
43+
44+
func main() {
45+
w := &Web{
46+
Host: "web host",
47+
port: 1234,
48+
Timeout: 5 * time.Second,
49+
Rate: 0.32,
50+
Score: []float32{1.1, 2.2, 3.3},
51+
IP: []string{"192.168.1.1", "127.0.0.1", "localhost"},
52+
MySQL: struct {
53+
Name string
54+
port int64
55+
}{Name: "mysqldb", port: 3306},
56+
redis: &Redis{"rdb", 6379, Host{"adf", []string{"alias1", "alias2"}, Policy{"allow policy", "deny policy"}}},
57+
}
58+
// 调用pprint 格式化输出
59+
pprint.Format(w)
60+
}
61+
62+
```
63+
64+
65+

desc.jpg

49.3 KB
Loading

0 commit comments

Comments
 (0)