github.com/observiq/carbon@v0.9.11-0.20200820160507-1b872e368a5e/operator/builtin/transformer/noop.go (about) 1 package transformer 2 3 import ( 4 "context" 5 6 "github.com/observiq/carbon/entry" 7 "github.com/observiq/carbon/operator" 8 "github.com/observiq/carbon/operator/helper" 9 ) 10 11 func init() { 12 operator.Register("noop", func() operator.Builder { return NewNoopOperatorConfig("") }) 13 } 14 15 func NewNoopOperatorConfig(operatorID string) *NoopOperatorConfig { 16 return &NoopOperatorConfig{ 17 TransformerConfig: helper.NewTransformerConfig(operatorID, "noop"), 18 } 19 } 20 21 // NoopOperatorConfig is the configuration of a noop operator. 22 type NoopOperatorConfig struct { 23 helper.TransformerConfig `yaml:",inline"` 24 } 25 26 // Build will build a noop operator. 27 func (c NoopOperatorConfig) Build(context operator.BuildContext) (operator.Operator, error) { 28 transformerOperator, err := c.TransformerConfig.Build(context) 29 if err != nil { 30 return nil, err 31 } 32 33 noopOperator := &NoopOperator{ 34 TransformerOperator: transformerOperator, 35 } 36 37 return noopOperator, nil 38 } 39 40 // NoopOperator is an operator that performs no operations on an entry. 41 type NoopOperator struct { 42 helper.TransformerOperator 43 } 44 45 // Process will forward the entry to the next output without any alterations. 46 func (p *NoopOperator) Process(ctx context.Context, entry *entry.Entry) error { 47 p.Write(ctx, entry) 48 return nil 49 }