@@ -166,13 +166,8 @@ func (c *Config) PluginsDeclared() []string {
166
166
}
167
167
168
168
// OutputsDeclared returns the name of all outputs declared in the config.
169
- func (c * Config ) OutputsDeclared () []string {
170
- var names []string
171
- for name := range c .outputs {
172
- names = append (names , name )
173
- }
174
- sort .Strings (names )
175
- return names
169
+ func (c * Config ) OutputsDeclared () map [string ]outputs.Output {
170
+ return c .outputs
176
171
}
177
172
178
173
// ListTags returns a string of tags specified in the config,
@@ -394,20 +389,24 @@ func findField(fieldName string, value reflect.Value) reflect.Value {
394
389
return reflect.Value {}
395
390
}
396
391
397
- // A very limited merge. Merges the fields named in the fields parameter, replacing most values, but appending to arrays.
392
+ // A very limited merge. Merges the fields named in the fields parameter,
393
+ // replacing most values, but appending to arrays.
398
394
func mergeStruct (base , overlay interface {}, fields []string ) error {
399
395
baseValue := reflect .ValueOf (base ).Elem ()
400
396
overlayValue := reflect .ValueOf (overlay ).Elem ()
401
397
if baseValue .Kind () != reflect .Struct {
402
- return fmt .Errorf ("Tried to merge something that wasn't a struct: type %v was %v" , baseValue .Type (), baseValue .Kind ())
398
+ return fmt .Errorf ("Tried to merge something that wasn't a struct: type %v was %v" ,
399
+ baseValue .Type (), baseValue .Kind ())
403
400
}
404
401
if baseValue .Type () != overlayValue .Type () {
405
- return fmt .Errorf ("Tried to merge two different types: %v and %v" , baseValue .Type (), overlayValue .Type ())
402
+ return fmt .Errorf ("Tried to merge two different types: %v and %v" ,
403
+ baseValue .Type (), overlayValue .Type ())
406
404
}
407
405
for _ , field := range fields {
408
406
overlayFieldValue := findField (field , overlayValue )
409
407
if ! overlayFieldValue .IsValid () {
410
- return fmt .Errorf ("could not find field in %v matching %v" , overlayValue .Type (), field )
408
+ return fmt .Errorf ("could not find field in %v matching %v" ,
409
+ overlayValue .Type (), field )
411
410
}
412
411
baseFieldValue := findField (field , baseValue )
413
412
if overlayFieldValue .Kind () == reflect .Slice {
@@ -536,13 +535,22 @@ func LoadConfig(path string) (*Config, error) {
536
535
}
537
536
case "outputs" :
538
537
for outputName , outputVal := range subtbl .Fields {
539
- outputSubtbl , ok := outputVal .(* ast.Table )
540
- if ! ok {
541
- return nil , err
542
- }
543
- err = c .parseOutput (outputName , outputSubtbl )
544
- if err != nil {
545
- return nil , err
538
+ switch outputSubtbl := outputVal .(type ) {
539
+ case * ast.Table :
540
+ err = c .parseOutput (outputName , outputSubtbl , 0 )
541
+ if err != nil {
542
+ return nil , err
543
+ }
544
+ case []* ast.Table :
545
+ for id , t := range outputSubtbl {
546
+ err = c .parseOutput (outputName , t , id )
547
+ if err != nil {
548
+ return nil , err
549
+ }
550
+ }
551
+ default :
552
+ return nil , fmt .Errorf ("Unsupported config format: %s" ,
553
+ outputName )
546
554
}
547
555
}
548
556
default :
@@ -579,7 +587,7 @@ func (c *Config) parseAgent(agentAst *ast.Table) error {
579
587
}
580
588
581
589
// Parse an output config out of the given *ast.Table.
582
- func (c * Config ) parseOutput (name string , outputAst * ast.Table ) error {
590
+ func (c * Config ) parseOutput (name string , outputAst * ast.Table , id int ) error {
583
591
c .outputFieldsSet [name ] = extractFieldNames (outputAst )
584
592
creator , ok := outputs .Outputs [name ]
585
593
if ! ok {
@@ -590,7 +598,7 @@ func (c *Config) parseOutput(name string, outputAst *ast.Table) error {
590
598
if err != nil {
591
599
return err
592
600
}
593
- c .outputs [name ] = output
601
+ c .outputs [fmt . Sprintf ( "%s-%d" , name , id ) ] = output
594
602
return nil
595
603
}
596
604
0 commit comments