Files
新亮 4c37a7e6b5 feature(1.2.8): swagger 接口文档新增 Security
- 将 middleware 命名为 interceptor
- 将 deploy 命名为 deployments
- 移除 pkg/errno
- 使用 proposal 目录
- 优化代码
2021-11-28 13:25:27 +08:00

51 lines
831 B
Go

package debugs
import (
"fmt"
"time"
"github.com/xinliangnote/go-gin-api/pkg/trace"
)
type Option func(*option)
type Trace = trace.T
type option struct {
Trace *trace.Trace
Debug *trace.Debug
}
func newOption() *option {
return &option{}
}
func Println(key string, value interface{}, options ...Option) {
ts := time.Now()
opt := newOption()
defer func() {
if opt.Trace != nil {
opt.Debug.Key = key
opt.Debug.Value = value
opt.Debug.CostSeconds = time.Since(ts).Seconds()
opt.Trace.AppendDebug(opt.Debug)
}
}()
for _, f := range options {
f(opt)
}
fmt.Println(fmt.Sprintf("KEY: %s | VALUE: %v", key, value))
}
// WithTrace 设置trace信息
func WithTrace(t Trace) Option {
return func(opt *option) {
if t != nil {
opt.Trace = t.(*trace.Trace)
opt.Debug = new(trace.Debug)
}
}
}