decode_go116.go 358 B

12345678910111213141516171819
  1. //go:build go1.16
  2. // +build go1.16
  3. package toml
  4. import (
  5. "io/fs"
  6. )
  7. // DecodeFS reads the contents of a file from [fs.FS] and decodes it with
  8. // [Decode].
  9. func DecodeFS(fsys fs.FS, path string, v interface{}) (MetaData, error) {
  10. fp, err := fsys.Open(path)
  11. if err != nil {
  12. return MetaData{}, err
  13. }
  14. defer fp.Close()
  15. return NewDecoder(fp).Decode(v)
  16. }