Documentation
¶
Overview ¶
Package vfs is the file-access seam between dtctl commands and the filesystem. CLI invocations read and write the host filesystem directly (the default). Embedded invocations (the service engine, `dtctl serve`) install a per-request FS — typically a MapFS built from the request's virtual files — so `apply -f x.yaml` works against files that exist only in the request, and writebacks (e.g. `apply --write-id`) land back in the request instead of on the host (docs/dev/SERVICE_ENGINE_DESIGN.md).
Only user-supplied paths go through this seam. Internal scratch files (editor round-trip temp files, spill buffers, caches) deliberately stay on the host filesystem: they are implementation detail, not request state.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Key ¶
Key is the name a MapFS keeps a file under: "x.yaml", "./x.yaml" and "/x.yaml" are one file. A caller matching paths against the files it hands a MapFS uses it instead of a rule of its own.
func ReadFileOrStdin ¶
ReadFileOrStdin reads name through the active FS, with "-" meaning the process stdin. It is the shared implementation behind the CLI's file-or-stdin flag convention.
Types ¶
type Env ¶
Env is one invocation's view of the host for user-supplied paths: the filesystem they resolve against and the stream "-" reads from. An embedder that runs invocations concurrently hands each its own Env, because the package-level state below is swapped for the whole process and so can serve only one invocation at a time.
The zero value is the process default: the installed FS and os.Stdin, so a caller that never sets one behaves exactly as before.
func (Env) ReadFileOrStdin ¶
ReadFileOrStdin reads name through e's FS, with "-" meaning e's stdin.
func (Env) StdinReader ¶
StdinReader is the stream "-" reads from: e's, else the process's.
type FS ¶
type FS interface {
ReadFile(name string) ([]byte, error)
WriteFile(name string, data []byte, perm fs.FileMode) error
}
FS is the minimal file-access contract dtctl commands need for user-supplied paths: whole-file reads and whole-file writes.
type MapFS ¶
type MapFS struct {
// contains filtered or unexported fields
}
MapFS is an in-memory FS for embedded invocations: the request's virtual files go in, and anything the invocation writes (writebacks, generated files) can be read back out with Files. Safe for concurrent use.
Paths are normalized with path.Clean and a stripped leading "/", so "./x.yaml", "x.yaml" and "/x.yaml" address the same entry — a request's virtual namespace has no meaningful root or working directory.
func NewMapFS ¶
NewMapFS builds a MapFS from the given files (copied; the input map is not retained). A nil map yields an empty filesystem.