env

package
v0.2.20 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2025 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrNilDestination              = "destination cannot be nil for the given key: %v"
	ErrEnvironmentVariableNotFound = "environment variable not found: %v"
	ErrInvalidDuration             = "invalid key '%v' duration value: %v"
	ErrInvalidInteger              = "invalid key '%v' integer value: %v"
)

Variables

View Source
var (
	ErrNilLoader                        = errors.New("loader cannot be nil")
	ErrFailedToLoadEnvironmentVariables = errors.New("failed to load environment variables")
)

Functions

func EnvironmentVariableLoaded added in v0.2.18

func EnvironmentVariableLoaded(logger *slog.Logger, variablesName ...string)

EnvironmentVariableLoaded logs a message when an environment variable is loaded

Parameters:

  • logger: The slog.Logger instance to use for logging.
  • variablesName: A variadic list of environment variable names that were loaded.

Types

type DefaultLoader added in v0.2.4

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

DefaultLoader struct

func NewDefaultLoader added in v0.2.4

func NewDefaultLoader(loadFn func() error, logger *slog.Logger) (
	*DefaultLoader,
	error,
)

NewDefaultLoader creates a new default environment variable loader

Parameters:

  • loadFn: function to load the environment variables (e.g., from a file)
  • logger: logger instance for logging

Returns:

  • *DefaultLoader: instance of DefaultLoader
  • error: error if any occurred during loading

func (DefaultLoader) LoadDurationVariable added in v0.2.4

func (d DefaultLoader) LoadDurationVariable(
	key string,
	dest *time.Duration,
) error

LoadDurationVariable load duration variable from environment variables

Parameters:

  • key: environment variable key
  • dest: pointer to the destination time.Duration where the value will be stored

Returns:

  • error: error if any occurred during loading or parsing

func (DefaultLoader) LoadIntVariable added in v0.2.4

func (d DefaultLoader) LoadIntVariable(key string, dest *int) error

LoadIntVariable load integer variable from environment variables

Parameters:

  • key: environment variable key
  • dest: pointer to the destination int where the value will be stored

Returns:

  • error: error if any occurred during loading or parsing

func (DefaultLoader) LoadSecondsVariable added in v0.2.4

func (d DefaultLoader) LoadSecondsVariable(key string, dest *float64) error

LoadSecondsVariable load duration variable in seconds from environment variables

Parameters:

  • key: environment variable key
  • dest: pointer to the destination float64 where the value in seconds will be stored

Returns:

  • error: error if any occurred during loading or parsing

func (DefaultLoader) LoadVariable added in v0.2.4

func (d DefaultLoader) LoadVariable(key string, dest *string) error

LoadVariable load variable from environment variables

Parameters:

  • key: environment variable key
  • dest: pointer to the destination string where the value will be stored

Returns:

  • error: error if any occurred during loading or parsing

type Loader added in v0.2.4

type Loader interface {
	LoadVariable(key string, dest *string) error
	LoadDurationVariable(key string, dest *time.Duration) error
	LoadSecondsVariable(key string, dest *float64) error
	LoadIntVariable(key string, dest *int) error
}

Loader interface for loading environment variables

Jump to

Keyboard shortcuts

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