iperf3exporter/vendor/github.com/goreleaser/chglog/files.go
Marvin Preuss 2343c9588a
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is failing
first commit
2021-10-20 10:08:56 +02:00

37 lines
787 B
Go

package chglog
import (
"fmt"
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
)
// Parse parse a changelog.yml into ChangeLogEntries.
func Parse(file string) (entries ChangeLogEntries, err error) {
var (
body []byte
)
body, err = ioutil.ReadFile(file) // nolint: gosec,gocritic
switch {
case os.IsNotExist(err):
return make(ChangeLogEntries, 0), nil
case err != nil:
return nil, fmt.Errorf("error parsing %s: %w", file, err)
}
if err = yaml.Unmarshal(body, &entries); err != nil {
return entries, fmt.Errorf("error parsing %s: %w", file, err)
}
return entries, nil
}
// Save save ChangeLogEntries to a yml file.
func (c *ChangeLogEntries) Save(file string) (err error) {
data, _ := yaml.Marshal(c)
// nolint: gosec,gocritic
return ioutil.WriteFile(file, data, 0644)
}