Skip to content

Commit

Permalink
Implement easy to use method for outputting various oscal formats
Browse files Browse the repository at this point in the history
  • Loading branch information
isimluk committed Nov 23, 2020
1 parent ea24ad5 commit d3253ef
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions types/oscal/oscal.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"encoding/xml"
"errors"
"fmt"
"io"
"io/ioutil"

Expand Down Expand Up @@ -217,6 +218,19 @@ func (o *OSCAL) YAML(w io.Writer) error {
return o.encode(encodeOptions{format: "yaml", writer: w})
}

// Write marshals OSCAL object as xml, json, or yaml
func (o *OSCAL) Write(w io.Writer, format constants.DocumentFormat, prettify bool) error {
switch format {
case constants.XmlFormat:
return o.XML(w, prettify)
case constants.JsonFormat:
return o.JSON(w, prettify)
case constants.YamlFormat:
return o.YAML(w)
}
return fmt.Errorf("Unrecognized document format requested: %s", format.String())
}

type encodeOptions struct {
format string
prettify bool
Expand Down

0 comments on commit d3253ef

Please sign in to comment.