github.com/Jeffail/benthos/v3@v3.65.0/lib/stream/config.go (about) 1 package stream 2 3 import ( 4 "github.com/Jeffail/benthos/v3/internal/docs" 5 "github.com/Jeffail/benthos/v3/lib/buffer" 6 "github.com/Jeffail/benthos/v3/lib/input" 7 "github.com/Jeffail/benthos/v3/lib/output" 8 "github.com/Jeffail/benthos/v3/lib/pipeline" 9 "gopkg.in/yaml.v3" 10 ) 11 12 //------------------------------------------------------------------------------ 13 14 // Config is a configuration struct representing all four layers of a Benthos 15 // stream. 16 type Config struct { 17 Input input.Config `json:"input" yaml:"input"` 18 Buffer buffer.Config `json:"buffer" yaml:"buffer"` 19 Pipeline pipeline.Config `json:"pipeline" yaml:"pipeline"` 20 Output output.Config `json:"output" yaml:"output"` 21 } 22 23 // NewConfig returns a new configuration with default values. 24 func NewConfig() Config { 25 return Config{ 26 Input: input.NewConfig(), 27 Buffer: buffer.NewConfig(), 28 Pipeline: pipeline.NewConfig(), 29 Output: output.NewConfig(), 30 } 31 } 32 33 // Sanitised returns a sanitised copy of the Benthos configuration, meaning 34 // fields of no consequence (unused inputs, outputs, processors etc) are 35 // excluded. 36 func (c Config) Sanitised() (interface{}, error) { 37 var node yaml.Node 38 if err := node.Encode(c); err != nil { 39 return nil, err 40 } 41 42 if err := Spec().SanitiseYAML(&node, docs.SanitiseConfig{ 43 RemoveTypeField: true, 44 }); err != nil { 45 return nil, err 46 } 47 48 var g interface{} 49 if err := node.Decode(&g); err != nil { 50 return nil, err 51 } 52 return g, nil 53 } 54 55 //------------------------------------------------------------------------------