github.com/observiq/carbon@v0.9.11-0.20200820160507-1b872e368a5e/operator/helper/output.go (about)

     1  package helper
     2  
     3  import (
     4  	"github.com/observiq/carbon/errors"
     5  	"github.com/observiq/carbon/operator"
     6  )
     7  
     8  func NewOutputConfig(operatorID, operatorType string) OutputConfig {
     9  	return OutputConfig{
    10  		BasicConfig: NewBasicConfig(operatorID, operatorType),
    11  	}
    12  }
    13  
    14  // OutputConfig provides a basic implementation of an output operator config.
    15  type OutputConfig struct {
    16  	BasicConfig `mapstructure:",squash" yaml:",inline"`
    17  }
    18  
    19  // Build will build an output operator.
    20  func (c OutputConfig) Build(context operator.BuildContext) (OutputOperator, error) {
    21  	basicOperator, err := c.BasicConfig.Build(context)
    22  	if err != nil {
    23  		return OutputOperator{}, err
    24  	}
    25  
    26  	outputOperator := OutputOperator{
    27  		BasicOperator: basicOperator,
    28  	}
    29  
    30  	return outputOperator, nil
    31  }
    32  
    33  // SetNamespace will namespace the id and output of the operator config.
    34  func (c *OutputConfig) SetNamespace(namespace string, exclusions ...string) {
    35  	if CanNamespace(c.ID(), exclusions) {
    36  		c.OperatorID = AddNamespace(c.ID(), namespace)
    37  	}
    38  }
    39  
    40  // OutputOperator provides a basic implementation of an output operator.
    41  type OutputOperator struct {
    42  	BasicOperator
    43  }
    44  
    45  // CanProcess will always return true for an output operator.
    46  func (o *OutputOperator) CanProcess() bool {
    47  	return true
    48  }
    49  
    50  // CanOutput will always return false for an output operator.
    51  func (o *OutputOperator) CanOutput() bool {
    52  	return false
    53  }
    54  
    55  // Outputs will always return an empty array for an output operator.
    56  func (o *OutputOperator) Outputs() []operator.Operator {
    57  	return []operator.Operator{}
    58  }
    59  
    60  // SetOutputs will return an error if called.
    61  func (o *OutputOperator) SetOutputs(operators []operator.Operator) error {
    62  	return errors.NewError(
    63  		"Operator can not output, but is attempting to set an output.",
    64  		"This is an unexpected internal error. Please submit a bug/issue.",
    65  	)
    66  }