configloader

package
v1.4.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

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

type CalyptiaConfig struct {
	Token string
	URL   string
	TLS   bool
}

CalyptiaConfig contains configurations related to Calyptia.

type FileReader

type FileReader interface {
	ReadFile(filename string) ([]byte, error)
}

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.

func (RealFileReader) ReadFile

func (r RealFileReader) ReadFile(filename string) ([]byte, error)

ReadFile reads the content of the given filename.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL