diff options
author | Ian Ling <ian@iancaling.com> | 2022-04-25 14:58:39 -0700 |
---|---|---|
committer | Ian Ling <ian@iancaling.com> | 2022-04-26 10:09:05 -0700 |
commit | 065db9a899b51b0f532ae7f8e15bfd145734455f (patch) | |
tree | ebaa98aeb5103e61a3edec138ccb6bfa886b31ab /yaml/parser.go | |
parent | 3c7fd178c3b4be6b987a7cd7e1d388dd96e38264 (diff) | |
download | spdx-tools-065db9a899b51b0f532ae7f8e15bfd145734455f.tar.gz |
Add YAML support
Signed-off-by: Ian Ling <ian@iancaling.com>
Diffstat (limited to 'yaml/parser.go')
-rw-r--r-- | yaml/parser.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/yaml/parser.go b/yaml/parser.go new file mode 100644 index 0000000..ca852dd --- /dev/null +++ b/yaml/parser.go @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +package spdx_yaml + +import ( + "bytes" + "io" + "sigs.k8s.io/yaml" + + "github.com/spdx/tools-golang/spdx" +) + +// Load2_2 takes in an io.Reader and returns an SPDX document. +func Load2_2(content io.Reader) (*spdx.Document2_2, error) { + // convert io.Reader to a slice of bytes and call the parser + buf := new(bytes.Buffer) + _, err := buf.ReadFrom(content) + if err != nil { + return nil, err + } + + var doc spdx.Document2_2 + err = yaml.Unmarshal(buf.Bytes(), &doc) + if err != nil { + return nil, err + } + + return &doc, nil +} |