...

Source file src/golang.conradwood.net/go-easyops/utils/functionchain/default_function_wrappers.go

Documentation: golang.conradwood.net/go-easyops/utils/functionchain

     1  package functionchain
     2  
     3  import "context"
     4  
     5  // shortcut: add a pair of enable/disable functions
     6  func (fc *FunctionChain) AddFuncs(enable, disable func(context.Context) error) *function_ref {
     7  	frw := &function_ref_wrapper{
     8  		enable_function:  enable,
     9  		disable_function: disable,
    10  	}
    11  	return fc.Add(frw)
    12  }
    13  
    14  type function_ref_wrapper struct {
    15  	enable_function  func(ctx context.Context) error
    16  	disable_function func(ctx context.Context) error
    17  }
    18  
    19  func (frw *function_ref_wrapper) SetTo(ctx context.Context, b bool) error {
    20  	if b {
    21  		return frw.enable_function(ctx)
    22  	}
    23  	return frw.disable_function(ctx)
    24  }
    25  
    26  /*
    27   ***********************************************************************************************
    28   */
    29  
    30  type function_ref_setter_wrapper struct {
    31  	setter func(context.Context, bool) error
    32  }
    33  
    34  // shortcut: add a pair of enable/disable functions
    35  func (fc *FunctionChain) AddSetter(setter func(context.Context, bool) error) *function_ref {
    36  	frw := &function_ref_setter_wrapper{
    37  		setter: setter,
    38  	}
    39  	return fc.Add(frw)
    40  }
    41  func (frw *function_ref_setter_wrapper) SetTo(ctx context.Context, b bool) error {
    42  	return frw.setter(ctx, b)
    43  }
    44  

View as plain text