github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/trace/discovery_gtrace.go (about)

     1  // Code generated by gtrace. DO NOT EDIT.
     2  
     3  package trace
     4  
     5  import (
     6  	"context"
     7  )
     8  
     9  // discoveryComposeOptions is a holder of options
    10  type discoveryComposeOptions struct {
    11  	panicCallback func(e interface{})
    12  }
    13  
    14  // DiscoveryOption specified Discovery compose option
    15  type DiscoveryComposeOption func(o *discoveryComposeOptions)
    16  
    17  // WithDiscoveryPanicCallback specified behavior on panic
    18  func WithDiscoveryPanicCallback(cb func(e interface{})) DiscoveryComposeOption {
    19  	return func(o *discoveryComposeOptions) {
    20  		o.panicCallback = cb
    21  	}
    22  }
    23  
    24  // Compose returns a new Discovery which has functional fields composed both from t and x.
    25  func (t *Discovery) Compose(x *Discovery, opts ...DiscoveryComposeOption) *Discovery {
    26  	var ret Discovery
    27  	options := discoveryComposeOptions{}
    28  	for _, opt := range opts {
    29  		if opt != nil {
    30  			opt(&options)
    31  		}
    32  	}
    33  	{
    34  		h1 := t.OnDiscover
    35  		h2 := x.OnDiscover
    36  		ret.OnDiscover = func(d DiscoveryDiscoverStartInfo) func(DiscoveryDiscoverDoneInfo) {
    37  			if options.panicCallback != nil {
    38  				defer func() {
    39  					if e := recover(); e != nil {
    40  						options.panicCallback(e)
    41  					}
    42  				}()
    43  			}
    44  			var r, r1 func(DiscoveryDiscoverDoneInfo)
    45  			if h1 != nil {
    46  				r = h1(d)
    47  			}
    48  			if h2 != nil {
    49  				r1 = h2(d)
    50  			}
    51  			return func(d DiscoveryDiscoverDoneInfo) {
    52  				if options.panicCallback != nil {
    53  					defer func() {
    54  						if e := recover(); e != nil {
    55  							options.panicCallback(e)
    56  						}
    57  					}()
    58  				}
    59  				if r != nil {
    60  					r(d)
    61  				}
    62  				if r1 != nil {
    63  					r1(d)
    64  				}
    65  			}
    66  		}
    67  	}
    68  	{
    69  		h1 := t.OnWhoAmI
    70  		h2 := x.OnWhoAmI
    71  		ret.OnWhoAmI = func(d DiscoveryWhoAmIStartInfo) func(DiscoveryWhoAmIDoneInfo) {
    72  			if options.panicCallback != nil {
    73  				defer func() {
    74  					if e := recover(); e != nil {
    75  						options.panicCallback(e)
    76  					}
    77  				}()
    78  			}
    79  			var r, r1 func(DiscoveryWhoAmIDoneInfo)
    80  			if h1 != nil {
    81  				r = h1(d)
    82  			}
    83  			if h2 != nil {
    84  				r1 = h2(d)
    85  			}
    86  			return func(d DiscoveryWhoAmIDoneInfo) {
    87  				if options.panicCallback != nil {
    88  					defer func() {
    89  						if e := recover(); e != nil {
    90  							options.panicCallback(e)
    91  						}
    92  					}()
    93  				}
    94  				if r != nil {
    95  					r(d)
    96  				}
    97  				if r1 != nil {
    98  					r1(d)
    99  				}
   100  			}
   101  		}
   102  	}
   103  	return &ret
   104  }
   105  func (t *Discovery) onDiscover(d DiscoveryDiscoverStartInfo) func(DiscoveryDiscoverDoneInfo) {
   106  	fn := t.OnDiscover
   107  	if fn == nil {
   108  		return func(DiscoveryDiscoverDoneInfo) {
   109  			return
   110  		}
   111  	}
   112  	res := fn(d)
   113  	if res == nil {
   114  		return func(DiscoveryDiscoverDoneInfo) {
   115  			return
   116  		}
   117  	}
   118  	return res
   119  }
   120  func (t *Discovery) onWhoAmI(d DiscoveryWhoAmIStartInfo) func(DiscoveryWhoAmIDoneInfo) {
   121  	fn := t.OnWhoAmI
   122  	if fn == nil {
   123  		return func(DiscoveryWhoAmIDoneInfo) {
   124  			return
   125  		}
   126  	}
   127  	res := fn(d)
   128  	if res == nil {
   129  		return func(DiscoveryWhoAmIDoneInfo) {
   130  			return
   131  		}
   132  	}
   133  	return res
   134  }
   135  func DiscoveryOnDiscover(t *Discovery, c *context.Context, call call, address string, database string) func(location string, endpoints []EndpointInfo, _ error) {
   136  	var p DiscoveryDiscoverStartInfo
   137  	p.Context = c
   138  	p.Call = call
   139  	p.Address = address
   140  	p.Database = database
   141  	res := t.onDiscover(p)
   142  	return func(location string, endpoints []EndpointInfo, e error) {
   143  		var p DiscoveryDiscoverDoneInfo
   144  		p.Location = location
   145  		p.Endpoints = endpoints
   146  		p.Error = e
   147  		res(p)
   148  	}
   149  }
   150  func DiscoveryOnWhoAmI(t *Discovery, c *context.Context, call call) func(user string, groups []string, _ error) {
   151  	var p DiscoveryWhoAmIStartInfo
   152  	p.Context = c
   153  	p.Call = call
   154  	res := t.onWhoAmI(p)
   155  	return func(user string, groups []string, e error) {
   156  		var p DiscoveryWhoAmIDoneInfo
   157  		p.User = user
   158  		p.Groups = groups
   159  		p.Error = e
   160  		res(p)
   161  	}
   162  }