1 Star 0 Fork 0

bughou / go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
key.go 561 Bytes
一键复制 编辑 原始数据 按行查看 历史
bughou 提交于 2022-03-20 18:50 . save
package tracer
import "context"
var key keyType
var debugKey debugKeyType
type keyType struct{}
type debugKeyType struct{}
func Get(ctx context.Context) *Tracer {
if ctx != nil {
if v := ctx.Value(key); v != nil {
if t, ok := v.(*Tracer); ok {
return t
}
}
}
return nil
}
func IsDebug(ctx context.Context) bool {
if ctx == nil {
return false
}
v := ctx.Value(debugKey)
b, _ := v.(bool)
return b
}
func SetDebug(ctx context.Context) context.Context {
if ctx != nil {
ctx = context.WithValue(ctx, debugKey, true)
}
return ctx
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/bughou/go.git
git@gitee.com:bughou/go.git
bughou
go
go
d31700df43a9

搜索帮助

344bd9b3 5694891 D2dac590 5694891