github.com/docker/app@v0.9.1-beta3.0.20210611140623-a48f773ab002/internal/formatter/yaml/driver.go (about)

     1  package yaml
     2  
     3  import (
     4  	"github.com/docker/app/internal/formatter"
     5  	"github.com/docker/app/internal/yaml"
     6  	composetypes "github.com/docker/cli/cli/compose/types"
     7  	"github.com/pkg/errors"
     8  )
     9  
    10  func init() {
    11  	formatter.Register("yaml", &Driver{})
    12  }
    13  
    14  // Driver is the yaml implementation of formatter drivers.
    15  type Driver struct{}
    16  
    17  // Format creates a YAML document from the source config.
    18  func (d *Driver) Format(config *composetypes.Config) (string, error) {
    19  	result, err := yaml.Marshal(config)
    20  	if err != nil {
    21  		return "", errors.Wrap(err, "failed to produce yaml structure")
    22  	}
    23  	return string(result), nil
    24  }