Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidOutValue is returned when a load function is passed an invalid out parameter. ErrInvalidOutValue = errors.New("invalid out value") // ErrLoadFailed is returned when a file failed to be loaded. ErrLoadFailed = errors.New("failed to load file") )
Functions ¶
func LoadDirFiles ¶
LoadDirFiles loads files contained in a directory into a target slice. Only a single directory level is loaded. Subdirectories are ignored. Failure to read a file will eventually be returned as an error, but will not stop the function from loading the rest of files in the target directory. `path` must be a directory path. `out` must be a map. The map must have string keys and pointer to interface type the files will be placed in as values (e.g. map[string]*Target). The keys of the map will contain filenames of loaded files, and the values will contain the loaded files.
The return value will contain all errors found when attempting to load files. Returned error types can be checked using `errors.Is`. Errors of type ErrLoadFailed indicate that the file was not accessible. It is up to the caller to consider this a critical error. All other errors are critical.
Types ¶
type Loader ¶
type Loader interface { // Load loads a file from a specific path into the passed output value. // Loaders that do not use files can ignore the `path` parameter. Load(path string, out interface{}) error // TrimExt returns the filename without the file extension. // Loaders should remove the extension of the file they expect as config. // - A YAML Loader will remove the `.yaml` extension. // - A JSON Loader will remove the `.json` extension. TrimExt(filename string) string // Filter returns the list of files that match the extension this Loader can process. Filter(list []string) []string }
Loader reads and parses files into Go structs
func NewYAMLLoader ¶
func NewYAMLLoader(logger gz.Logger) Loader
NewYAMLLoader returns a YAML loader.