Documentation
¶
Overview ¶
Package configloader provides functionality to load Calyptia configurations from a set of specified configuration files. The main purpose of this package is to provide a simplified and streamlined way to fetch configurations without relying on environment variables.
The package introduces a `Loader` type, which is responsible for loading and parsing the configuration files. It leverages the FileReader interface to read file contents, which allows for easy mocking in unit tests.
Usage:
loader := configloader.NewLoader(nil) // uses the real file reader by default
config := loader.LoadFromFiles("path/to/config1.yaml", "path/to/config2.conf")
if config != nil {
fmt.Println("Loaded config:", config)
}
The package also supports multiple file formats, including `.conf`, `.ini`, `.yaml`, and `.yml`. The first valid Calyptia configuration found among the provided files will be returned. If none is found, the function returns nil.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CalyptiaConfig ¶
CalyptiaConfig contains configurations related to Calyptia.
type FileReader ¶
FileReader is an interface for reading files.
type Loader ¶
type Loader struct {
FileReader
}
Loader is responsible for loading configurations.
func NewDefaultLoader ¶
func NewDefaultLoader() *Loader
NewDefaultLoader returns a new Loader instance with the default real file reader.
func NewLoader ¶
func NewLoader(fr FileReader) *Loader
NewLoader initializes a new Loader with the given FileReader.
func (*Loader) LoadFromFiles ¶
func (cl *Loader) LoadFromFiles(configFiles ...string) *CalyptiaConfig
LoadFromFiles loads the Calyptia configurations from the given list of files. It goes through each file, parses it, and attempts to retrieve the Calyptia configuration. The method returns the first valid Calyptia configuration it finds.
type LoaderInterface ¶
type LoaderInterface interface {
LoadFromFiles(configFiles ...string) *CalyptiaConfig
}
LoaderInterface is an interface for the configuration loader.
type RealFileReader ¶
type RealFileReader struct{}
RealFileReader is a concrete implementation of FileReader.