/
githubmirror
/
ydb-go-sql
Обзор
Документация
Войти
/
githubmirror
/
ydb-go-sql
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
internal/trace/trace_gtrace.go
107 строк
2 KB
asmyasnikov
draft
18 дек 2021, 14:18
18 дек 2021, 14:18
4ee29e6
Код
Авторство
О чём код?
// Code generated by gtrace. DO NOT EDIT. package trace import ( "context" ) // Compose returns a new Trace which has functional fields composed // both from t and x. func (t Trace) Compose(x Trace) (ret Trace) { switch { case t.OnDial == nil: ret.OnDial = x.OnDial case x.OnDial == nil: ret.OnDial = t.OnDial default: h1 := t.OnDial h2 := x.OnDial ret.OnDial = func(d DialStartInfo) func(DialDoneInfo) { r1 := h1(d) r2 := h2(d) switch { case r1 == nil: return r2 case r2 == nil: return r1 default: return func(d DialDoneInfo) { r1(d) r2(d) } } } } return ret } type traceContextKey struct{} // WithTrace returns context which has associated Trace with it. func WithTrace(ctx context.Context, t Trace) context.Context { return context.WithValue(ctx, traceContextKey{}, ContextTrace(ctx).Compose(t), ) } // ContextTrace returns Trace associated with x. // If there is no Trace associated with x then zero value // of Trace is returned. func ContextTrace(ctx context.Context) Trace { t, _ := ctx.Value(traceContextKey{}).(Trace) return t } func (t Trace) onDial(ctx context.Context, d DialStartInfo) func(DialDoneInfo) { c := ContextTrace(ctx) var fn func(DialStartInfo) func(DialDoneInfo) switch { case t.OnDial == nil: fn = c.OnDial case c.OnDial == nil: fn = t.OnDial default: h1 := t.OnDial h2 := c.OnDial fn = func(d DialStartInfo) func(DialDoneInfo) { r1 := h1(d) r2 := h2(d) switch { case r1 == nil: return r2 case r2 == nil: return r1 default: return func(d DialDoneInfo) { r1(d) r2(d) } } } } if fn == nil { return func(DialDoneInfo) { return } } res := fn(d) if res == nil { return func(DialDoneInfo) { return } } return res } func traceOnDial(ctx context.Context, t Trace, c context.Context) func(context.Context, error) { var p DialStartInfo p.Context = c res := t.onDial(ctx, p) return func(c context.Context, e error) { var p DialDoneInfo p.Context = c p.Error = e res(p) } }