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

     1  // Code generated by gtrace. DO NOT EDIT.
     2  
     3  package trace
     4  
     5  import (
     6  	"context"
     7  )
     8  
     9  // scriptingComposeOptions is a holder of options
    10  type scriptingComposeOptions struct {
    11  	panicCallback func(e interface{})
    12  }
    13  
    14  // ScriptingOption specified Scripting compose option
    15  type ScriptingComposeOption func(o *scriptingComposeOptions)
    16  
    17  // WithScriptingPanicCallback specified behavior on panic
    18  func WithScriptingPanicCallback(cb func(e interface{})) ScriptingComposeOption {
    19  	return func(o *scriptingComposeOptions) {
    20  		o.panicCallback = cb
    21  	}
    22  }
    23  
    24  // Compose returns a new Scripting which has functional fields composed both from t and x.
    25  func (t *Scripting) Compose(x *Scripting, opts ...ScriptingComposeOption) *Scripting {
    26  	var ret Scripting
    27  	options := scriptingComposeOptions{}
    28  	for _, opt := range opts {
    29  		if opt != nil {
    30  			opt(&options)
    31  		}
    32  	}
    33  	{
    34  		h1 := t.OnExecute
    35  		h2 := x.OnExecute
    36  		ret.OnExecute = func(s ScriptingExecuteStartInfo) func(ScriptingExecuteDoneInfo) {
    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(ScriptingExecuteDoneInfo)
    45  			if h1 != nil {
    46  				r = h1(s)
    47  			}
    48  			if h2 != nil {
    49  				r1 = h2(s)
    50  			}
    51  			return func(s ScriptingExecuteDoneInfo) {
    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(s)
    61  				}
    62  				if r1 != nil {
    63  					r1(s)
    64  				}
    65  			}
    66  		}
    67  	}
    68  	{
    69  		h1 := t.OnStreamExecute
    70  		h2 := x.OnStreamExecute
    71  		ret.OnStreamExecute = func(s ScriptingStreamExecuteStartInfo) func(ScriptingStreamExecuteIntermediateInfo) func(ScriptingStreamExecuteDoneInfo) {
    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(ScriptingStreamExecuteIntermediateInfo) func(ScriptingStreamExecuteDoneInfo)
    80  			if h1 != nil {
    81  				r = h1(s)
    82  			}
    83  			if h2 != nil {
    84  				r1 = h2(s)
    85  			}
    86  			return func(s ScriptingStreamExecuteIntermediateInfo) func(ScriptingStreamExecuteDoneInfo) {
    87  				if options.panicCallback != nil {
    88  					defer func() {
    89  						if e := recover(); e != nil {
    90  							options.panicCallback(e)
    91  						}
    92  					}()
    93  				}
    94  				var r2, r3 func(ScriptingStreamExecuteDoneInfo)
    95  				if r != nil {
    96  					r2 = r(s)
    97  				}
    98  				if r1 != nil {
    99  					r3 = r1(s)
   100  				}
   101  				return func(s ScriptingStreamExecuteDoneInfo) {
   102  					if options.panicCallback != nil {
   103  						defer func() {
   104  							if e := recover(); e != nil {
   105  								options.panicCallback(e)
   106  							}
   107  						}()
   108  					}
   109  					if r2 != nil {
   110  						r2(s)
   111  					}
   112  					if r3 != nil {
   113  						r3(s)
   114  					}
   115  				}
   116  			}
   117  		}
   118  	}
   119  	{
   120  		h1 := t.OnExplain
   121  		h2 := x.OnExplain
   122  		ret.OnExplain = func(s ScriptingExplainStartInfo) func(ScriptingExplainDoneInfo) {
   123  			if options.panicCallback != nil {
   124  				defer func() {
   125  					if e := recover(); e != nil {
   126  						options.panicCallback(e)
   127  					}
   128  				}()
   129  			}
   130  			var r, r1 func(ScriptingExplainDoneInfo)
   131  			if h1 != nil {
   132  				r = h1(s)
   133  			}
   134  			if h2 != nil {
   135  				r1 = h2(s)
   136  			}
   137  			return func(s ScriptingExplainDoneInfo) {
   138  				if options.panicCallback != nil {
   139  					defer func() {
   140  						if e := recover(); e != nil {
   141  							options.panicCallback(e)
   142  						}
   143  					}()
   144  				}
   145  				if r != nil {
   146  					r(s)
   147  				}
   148  				if r1 != nil {
   149  					r1(s)
   150  				}
   151  			}
   152  		}
   153  	}
   154  	{
   155  		h1 := t.OnClose
   156  		h2 := x.OnClose
   157  		ret.OnClose = func(s ScriptingCloseStartInfo) func(ScriptingCloseDoneInfo) {
   158  			if options.panicCallback != nil {
   159  				defer func() {
   160  					if e := recover(); e != nil {
   161  						options.panicCallback(e)
   162  					}
   163  				}()
   164  			}
   165  			var r, r1 func(ScriptingCloseDoneInfo)
   166  			if h1 != nil {
   167  				r = h1(s)
   168  			}
   169  			if h2 != nil {
   170  				r1 = h2(s)
   171  			}
   172  			return func(s ScriptingCloseDoneInfo) {
   173  				if options.panicCallback != nil {
   174  					defer func() {
   175  						if e := recover(); e != nil {
   176  							options.panicCallback(e)
   177  						}
   178  					}()
   179  				}
   180  				if r != nil {
   181  					r(s)
   182  				}
   183  				if r1 != nil {
   184  					r1(s)
   185  				}
   186  			}
   187  		}
   188  	}
   189  	return &ret
   190  }
   191  func (t *Scripting) onExecute(s ScriptingExecuteStartInfo) func(ScriptingExecuteDoneInfo) {
   192  	fn := t.OnExecute
   193  	if fn == nil {
   194  		return func(ScriptingExecuteDoneInfo) {
   195  			return
   196  		}
   197  	}
   198  	res := fn(s)
   199  	if res == nil {
   200  		return func(ScriptingExecuteDoneInfo) {
   201  			return
   202  		}
   203  	}
   204  	return res
   205  }
   206  func (t *Scripting) onStreamExecute(s ScriptingStreamExecuteStartInfo) func(ScriptingStreamExecuteIntermediateInfo) func(ScriptingStreamExecuteDoneInfo) {
   207  	fn := t.OnStreamExecute
   208  	if fn == nil {
   209  		return func(ScriptingStreamExecuteIntermediateInfo) func(ScriptingStreamExecuteDoneInfo) {
   210  			return func(ScriptingStreamExecuteDoneInfo) {
   211  				return
   212  			}
   213  		}
   214  	}
   215  	res := fn(s)
   216  	if res == nil {
   217  		return func(ScriptingStreamExecuteIntermediateInfo) func(ScriptingStreamExecuteDoneInfo) {
   218  			return func(ScriptingStreamExecuteDoneInfo) {
   219  				return
   220  			}
   221  		}
   222  	}
   223  	return func(s ScriptingStreamExecuteIntermediateInfo) func(ScriptingStreamExecuteDoneInfo) {
   224  		res := res(s)
   225  		if res == nil {
   226  			return func(ScriptingStreamExecuteDoneInfo) {
   227  				return
   228  			}
   229  		}
   230  		return res
   231  	}
   232  }
   233  func (t *Scripting) onExplain(s ScriptingExplainStartInfo) func(ScriptingExplainDoneInfo) {
   234  	fn := t.OnExplain
   235  	if fn == nil {
   236  		return func(ScriptingExplainDoneInfo) {
   237  			return
   238  		}
   239  	}
   240  	res := fn(s)
   241  	if res == nil {
   242  		return func(ScriptingExplainDoneInfo) {
   243  			return
   244  		}
   245  	}
   246  	return res
   247  }
   248  func (t *Scripting) onClose(s ScriptingCloseStartInfo) func(ScriptingCloseDoneInfo) {
   249  	fn := t.OnClose
   250  	if fn == nil {
   251  		return func(ScriptingCloseDoneInfo) {
   252  			return
   253  		}
   254  	}
   255  	res := fn(s)
   256  	if res == nil {
   257  		return func(ScriptingCloseDoneInfo) {
   258  			return
   259  		}
   260  	}
   261  	return res
   262  }
   263  func ScriptingOnExecute(t *Scripting, c *context.Context, call call, query string, parameters scriptingQueryParameters) func(result scriptingResult, _ error) {
   264  	var p ScriptingExecuteStartInfo
   265  	p.Context = c
   266  	p.Call = call
   267  	p.Query = query
   268  	p.Parameters = parameters
   269  	res := t.onExecute(p)
   270  	return func(result scriptingResult, e error) {
   271  		var p ScriptingExecuteDoneInfo
   272  		p.Result = result
   273  		p.Error = e
   274  		res(p)
   275  	}
   276  }
   277  func ScriptingOnStreamExecute(t *Scripting, c *context.Context, call call, query string, parameters scriptingQueryParameters) func(error) func(error) {
   278  	var p ScriptingStreamExecuteStartInfo
   279  	p.Context = c
   280  	p.Call = call
   281  	p.Query = query
   282  	p.Parameters = parameters
   283  	res := t.onStreamExecute(p)
   284  	return func(e error) func(error) {
   285  		var p ScriptingStreamExecuteIntermediateInfo
   286  		p.Error = e
   287  		res := res(p)
   288  		return func(e error) {
   289  			var p ScriptingStreamExecuteDoneInfo
   290  			p.Error = e
   291  			res(p)
   292  		}
   293  	}
   294  }
   295  func ScriptingOnExplain(t *Scripting, c *context.Context, call call, query string) func(plan string, _ error) {
   296  	var p ScriptingExplainStartInfo
   297  	p.Context = c
   298  	p.Call = call
   299  	p.Query = query
   300  	res := t.onExplain(p)
   301  	return func(plan string, e error) {
   302  		var p ScriptingExplainDoneInfo
   303  		p.Plan = plan
   304  		p.Error = e
   305  		res(p)
   306  	}
   307  }
   308  func ScriptingOnClose(t *Scripting, c *context.Context, call call) func(error) {
   309  	var p ScriptingCloseStartInfo
   310  	p.Context = c
   311  	p.Call = call
   312  	res := t.onClose(p)
   313  	return func(e error) {
   314  		var p ScriptingCloseDoneInfo
   315  		p.Error = e
   316  		res(p)
   317  	}
   318  }