cfg

package
v0.2.34 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: MIT Imports: 18 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateDefaultEnvs added in v0.2.17

func GenerateDefaultEnvs(cfg any, _ string, opts ...Option) error

func GenerateFlags added in v0.2.23

func GenerateFlags(cfg any, opts ...Option) (string, error)

func GenerateMarkdown added in v0.2.17

func GenerateMarkdown(cfg any, filePath string, opts ...Option) error

func GenerateYamlTemplate added in v0.2.16

func GenerateYamlTemplate(cfg any, filePath string, opts ...Option) error

func GetConfigLoader added in v0.2.29

func GetConfigLoader(cfg any, opts ...Option) (*aconfig.Loader, error)

GetConfigLoader returns aconfig loader instance.

func Load

func Load(cfg any, opts ...Option) error

Load environment variables from `os env`, flags, `.env`, `.yaml` files and pass it to struct.

For local development use `.env` file from root project.

Load also call a `Validate` method if it proided.

Example:

var config internalConfig.Config
if err := cfg.Load(&config); err != nil {
	logger.Fatalf("could not load configuration: %v", err)
}

func LoadForTests added in v0.0.10

func LoadForTests(cfg any, opts ...Option) error

LoadForTests environment variables from `os env`, flags, `.env`, `.yaml` files and pass it to struct.

Disabled flags detection and any cli features.

For local development use `.env` file from root project.

LoadForTests also call a `Validate` method if it proided.

Example:

var config internalConfig.Config
if err := cfg.LoadForTests(&config); err != nil {
	logger.Fatalf("could not load configuration: %v", err)
}

func ValidateConfig added in v0.2.17

func ValidateConfig(cfg any, opts ...Option) error

ValidateConfig validates config struct with environment variables and custom validation functions.

Types

type Config added in v0.2.17

type Config = aconfig.Config

type ConfigField added in v0.2.29

type ConfigField struct {
	Path              string
	EnvName           string
	DefaultValue      string
	Usage             string
	Example           string
	ValidateParams    string
	IsRequired        bool
	IsSecret          bool
	DisableValidation bool
}

func GetConfigFields added in v0.2.29

func GetConfigFields(loader *aconfig.Loader) []ConfigField

type Option

type Option func(*options)

func WithContext

func WithContext(v context.Context) Option

func WithLoaderConfig added in v0.2.17

func WithLoaderConfig(v Config) Option

WithEnvFile - path to dotenv config file.

func WithValidate

func WithValidate(v bool) Option

func WithValidateFuncs

func WithValidateFuncs(items ...ValidateFn) Option

type ValidateFn

type ValidateFn struct {
	Tag                      string
	Fn                       validator.Func
	CallValidationEvenIfNull []bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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