github.com/gobwas/gtrace@v0.4.3/test/test_imports_gtrace.go (about)

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