decode_go116.go 381 B

123456789101112131415161718
  1. // +build go1.16
  2. package toml
  3. import (
  4. "io/fs"
  5. )
  6. // DecodeFS is just like Decode, except it will automatically read the contents
  7. // of the file at `path` from a fs.FS instance.
  8. func DecodeFS(fsys fs.FS, path string, v interface{}) (MetaData, error) {
  9. fp, err := fsys.Open(path)
  10. if err != nil {
  11. return MetaData{}, err
  12. }
  13. defer fp.Close()
  14. return NewDecoder(fp).Decode(v)
  15. }