1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
// Package fs implements a koanf.Provider that reads raw bytes
// from given fs.FS to be used with a koanf.Parser to parse
// into conf maps.
//go:build go1.16
// +build go1.16
package fs
import (
"errors"
"io"
"io/fs"
)
// FS implements an fs.FS provider.
type FS struct {
fs fs.FS
path string
}
// Provider returns an fs.FS provider.
func Provider(fs fs.FS, filepath string) *FS {
return &FS{fs: fs, path: filepath}
}
// ReadBytes reads the contents of given filepath from fs.FS and returns the bytes.
func (f *FS) ReadBytes() ([]byte, error) {
fd, err := f.fs.Open(f.path)
if err != nil {
return nil, err
}
defer fd.Close()
return io.ReadAll(fd)
}
// Read is not supported by the fs.FS provider.
func (f *FS) Read() (map[string]interface{}, error) {
return nil, errors.New("fs.FS provider does not support this method")
}
|