Skip to content

Commit

Permalink
feat: function to parse a manifest from a ReaderCloser
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickkirschen committed May 29, 2024
1 parent b697d61 commit e78c436
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion manifesto.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package manifesto

import (
"errors"
"io"
"log"
"os"
"strings"
Expand Down Expand Up @@ -138,7 +139,23 @@ func ParseFile(filename string, spec any, status any) *Manifest {
log.Fatal("Error during unmarshal file: ", err)
}

err = manifest.Spec.Decode(spec)
return parseManifest(&manifest, spec, status)
}

// ParseReader parses JSON/YAML data from an io.ReadCloser into a Manifest.
func ParseReader(r io.ReadCloser, spec any, status any) *Manifest {
var manifest manifest
err := yaml.NewDecoder(r).Decode(&manifest)

if err != nil {
log.Fatal("Error during unmarshal data: ", err)
}

return parseManifest(&manifest, spec, status)
}

func parseManifest(manifest *manifest, spec any, status any) *Manifest {
err := manifest.Spec.Decode(spec)
if err != nil {
log.Fatal("Error during unmarshal spec: ", err)
}
Expand Down

0 comments on commit e78c436

Please sign in to comment.