github.com/Jeffail/benthos/v3@v3.65.0/lib/util/config/yaml.go (about)

     1  package config
     2  
     3  import (
     4  	"bytes"
     5  
     6  	yaml "gopkg.in/yaml.v3"
     7  )
     8  
     9  //------------------------------------------------------------------------------
    10  
    11  // MarshalYAML marshals a structure into YAML with consistent formatting across
    12  // all Benthos components.
    13  func MarshalYAML(v interface{}) ([]byte, error) {
    14  	var cbytes bytes.Buffer
    15  	enc := yaml.NewEncoder(&cbytes)
    16  	enc.SetIndent(2)
    17  	if err := enc.Encode(v); err != nil {
    18  		return nil, err
    19  	}
    20  	return cbytes.Bytes(), nil
    21  }
    22  
    23  //------------------------------------------------------------------------------