config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package config provides configuration loader and the interface for working with configuration.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrShouldStop is returned when the execution should be stopped. E.g. on -v and -h flags.
	ErrShouldStop = errors.New("execution should be stopped")
)

Additional errors to control the execution flow.

Functions

This section is empty.

Types

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader is a viper config loader.

func NewLoader

func NewLoader(name, short, long, configPath, envPrefix string) *Loader

NewLoader returns a new viper loader.

name is the short name of the service, as well as the name of the root command.

short and long are the short and long descriptions of the service for the root command.

configPath is the path to the configuration file.

envPrefix is the prefix for environment variables.

func (*Loader) Load

func (l *Loader) Load(cfg ServiceConfig, printVersion func(io.Writer) error, writer io.Writer) (ServiceConfig, error)

Load loads configuration from a file and environment variables. It checks the flags in the process and executes the root command, depending on the flag. If no additional flags are set, it will load the configuration from the path provided.

If -h (--help) or -v (--version) flags are set, it will return nil, ErrShouldStop as a signal to stop the execution.

type ServiceConfig

type ServiceConfig interface {
	// GetSubConfig returns the part of the config that corresponds to the key.
	GetSubConfig(key string) (map[string]any, error)
}

ServiceConfig is an interface generalizing service config.

Jump to

Keyboard shortcuts

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