Expose native filesystem sources through public loading API
This commit is contained in:
21
source.go
21
source.go
@@ -2,14 +2,31 @@ package configkit
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/fs"
|
||||
|
||||
"gitea.maximumdirect.net/eric/ConfigKit/internal/engine"
|
||||
)
|
||||
|
||||
// Source is an opaque configuration input. Construct sources with File, Bytes,
|
||||
// Reader, or NoSource; the zero value is invalid.
|
||||
// Source is an opaque configuration input. Construct sources with File,
|
||||
// Filesystem.File, Bytes, Reader, or NoSource; the zero value is invalid.
|
||||
type Source struct{ value engine.Source }
|
||||
|
||||
// Filesystem is a reusable opaque namespace for a caller-owned fs.FS. Copies
|
||||
// preserve identity; separately constructed values are distinct even if their
|
||||
// labels or underlying filesystems match. The filesystem is never closed.
|
||||
type Filesystem struct{ value engine.Filesystem }
|
||||
|
||||
// NewFilesystem borrows filesystem without opening it. Label must be nonempty
|
||||
// and safe to display; a nil filesystem or invalid label is reported when a
|
||||
// source from the returned namespace is consumed.
|
||||
func NewFilesystem(label string, filesystem fs.FS) Filesystem {
|
||||
return Filesystem{value: engine.NewFilesystem(label, filesystem)}
|
||||
}
|
||||
|
||||
// File selects a non-root fs.ValidPath name in this filesystem. Each load
|
||||
// reopens the file; constructor problems are reported when the source is used.
|
||||
func (f Filesystem) File(name string) Source { return Source{value: f.value.File(name)} }
|
||||
|
||||
// File returns a source that reopens path for every load attempt.
|
||||
func File(path string) Source { return Source{value: engine.File(path)} }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user