Documentation
¶
Overview ¶
Package configafero adapts an afero.Fs to the config.FS interface, so code already holding an afero filesystem can hand it to a config Store unchanged.
The config module defines its own six-method filesystem interface rather than depending on afero, so that importing it does not oblige a consumer to import a filesystem library chosen for them. This adapter is for consumers who have made that choice already — a tool built on afero, or one wrapping a copy-on-write or in-memory filesystem it needs configuration to read through.
store, err := config.NewStore(ctx, config.WithFiles(configafero.Wrap(myAferoFs), "/etc/app.yaml"))
If all you need is the real filesystem, you do not need this package: config.OS is that, with no dependency. And a test wanting a throwaway directory wants config.Dir over t.TempDir(), which gives real file semantics including watching.
Why this is not twenty lines you write yourself ¶
It very nearly is. Six methods map onto afero almost directly. The part worth not rediscovering is which *optional* interfaces the adapter may claim.
config asks whether a filesystem satisfies config.RealPather to decide whether native filesystem notification can work at all, and whether it satisfies config.LinkReader to decide whether a write should follow a symlink. An adapter implementing either method unconditionally satisfies the interface for every filesystem, including those that cannot honour it — so config takes a path it should not have, and finds out late or not at all.
Wrap therefore returns one of four types, claiming exactly the capabilities the wrapped filesystem actually has.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Wrap ¶
Wrap adapts an afero filesystem to config.FS.
The concrete type returned claims only what the filesystem can support: config.RealPather when it has operating-system paths, and config.LinkReader when it can resolve symlinks. A filesystem with neither gets the plain adapter, so config polls it and uses paths as given.
Types ¶
This section is empty.