github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/github/yaml/parse.go (about)

     1  package yaml
     2  
     3  import (
     4  	"bytes"
     5  	"io"
     6  	"os"
     7  
     8  	"gopkg.in/yaml.v3"
     9  )
    10  
    11  // Parse parses the configuration from io.Reader r.
    12  func Parse(r io.Reader) (*Pipeline, error) {
    13  	buf := repairOn(r)
    14  	out := new(Pipeline)
    15  	dec := yaml.NewDecoder(&buf)
    16  	err := dec.Decode(out)
    17  	return out, err
    18  }
    19  
    20  // ParseBytes parses the configuration from bytes b.
    21  func ParseBytes(b []byte) (*Pipeline, error) {
    22  	return Parse(
    23  		bytes.NewBuffer(b),
    24  	)
    25  }
    26  
    27  // ParseString parses the configuration from string s.
    28  func ParseString(s string) (*Pipeline, error) {
    29  	return ParseBytes(
    30  		[]byte(s),
    31  	)
    32  }
    33  
    34  // ParseFile parses the configuration from path p.
    35  func ParseFile(p string) (*Pipeline, error) {
    36  	f, err := os.Open(p)
    37  	if err != nil {
    38  		return nil, err
    39  	}
    40  	defer f.Close()
    41  	return Parse(f)
    42  }