https://github.com/goindow/toolbox
Package toolbox 封装了一些开发调试工具
https://github.com/goindow/toolbox
trace var-dump
Last synced: about 1 month ago
JSON representation
Package toolbox 封装了一些开发调试工具
- Host: GitHub
- URL: https://github.com/goindow/toolbox
- Owner: goindow
- Created: 2019-03-14T06:59:19.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-11T03:49:42.000Z (almost 5 years ago)
- Last Synced: 2025-01-21T16:23:15.283Z (3 months ago)
- Topics: trace, var-dump
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# toolbox
Package toolbox 封装了一些开发中使用的工具## 索引
- [Dump](#Dump)### 使用
```go
import (
"github.com/goindow/toolbox"
)
```### Dump
- 打印变量的类型和值,支持同时打印多个变量
- 本质是调用 fmt.Printf(),每个变量格式为 "[%T] %v\n"
```go
toolbox.Dump(os.Getwd())// Output:
// [string] /usr/local/var/go/src/github.com/goindow/toolbox
// []
```### Trace
- 计算函数/方法运行耗时
- 接收返回值,ret := trace(func2),ret 类型为 []reflect.value
```go
// 无参函数
trace(func1)
// 有返回值
ret := trace(fun2) // retInt := ret[0].Int()
// 有参函数
trace(func4, 3, true)
// 有参方法
trace(new(reflectStruct).func4, 5, false)// Output:
// call: main.func1
// time: 52.561µs
//
// call: main.func2
// time: 57.324µs
//
// call: main.func4
// time: 18.698µs
//
// call: main.(*reflectStruct).func4-fm
// time: 4.168µs
```