-
Notifications
You must be signed in to change notification settings - Fork 10
/
test_imports_gtrace.go
102 lines (94 loc) · 2.21 KB
/
test_imports_gtrace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Code generated by gtrace. DO NOT EDIT.
package test
import (
"context"
"github.com/gobwas/gtrace/test/internal"
)
// Compose returns a new TraceNoShortcut which has functional fields composed
// both from t and x.
func (t TraceNoShortcut) Compose(x TraceNoShortcut) (ret TraceNoShortcut) {
switch {
case t.OnSomethingA == nil:
ret.OnSomethingA = x.OnSomethingA
case x.OnSomethingA == nil:
ret.OnSomethingA = t.OnSomethingA
default:
h1 := t.OnSomethingA
h2 := x.OnSomethingA
ret.OnSomethingA = func(t Type) {
h1(t)
h2(t)
}
}
switch {
case t.OnSomethingB == nil:
ret.OnSomethingB = x.OnSomethingB
case x.OnSomethingB == nil:
ret.OnSomethingB = t.OnSomethingB
default:
h1 := t.OnSomethingB
h2 := x.OnSomethingB
ret.OnSomethingB = func(t internal.Type) {
h1(t)
h2(t)
}
}
return ret
}
type traceNoShortcutContextKey struct{}
// WithTraceNoShortcut returns context which has associated TraceNoShortcut with it.
func WithTraceNoShortcut(ctx context.Context, t TraceNoShortcut) context.Context {
return context.WithValue(ctx,
traceNoShortcutContextKey{},
ContextTraceNoShortcut(ctx).Compose(t),
)
}
// ContextTraceNoShortcut returns TraceNoShortcut associated with ctx.
// If there is no TraceNoShortcut associated with ctx then zero value
// of TraceNoShortcut is returned.
func ContextTraceNoShortcut(ctx context.Context) TraceNoShortcut {
t, _ := ctx.Value(traceNoShortcutContextKey{}).(TraceNoShortcut)
return t
}
func (t TraceNoShortcut) onSomethingA(ctx context.Context, t1 Type) {
c := ContextTraceNoShortcut(ctx)
var fn func(Type)
switch {
case t.OnSomethingA == nil:
fn = c.OnSomethingA
case c.OnSomethingA == nil:
fn = t.OnSomethingA
default:
h1 := t.OnSomethingA
h2 := c.OnSomethingA
fn = func(t Type) {
h1(t)
h2(t)
}
}
if fn == nil {
return
}
fn(t1)
}
func (t TraceNoShortcut) onSomethingB(ctx context.Context, t1 internal.Type) {
c := ContextTraceNoShortcut(ctx)
var fn func(internal.Type)
switch {
case t.OnSomethingB == nil:
fn = c.OnSomethingB
case c.OnSomethingB == nil:
fn = t.OnSomethingB
default:
h1 := t.OnSomethingB
h2 := c.OnSomethingB
fn = func(t internal.Type) {
h1(t)
h2(t)
}
}
if fn == nil {
return
}
fn(t1)
}