Documentation
¶
Index ¶
- func GenerateDefaultEnvs(cfg any, _ string, opts ...Option) error
- func GenerateFlags(cfg any, opts ...Option) (string, error)
- func GenerateMarkdown(cfg any, filePath string, opts ...Option) error
- func GenerateYamlTemplate(cfg any, filePath string, opts ...Option) error
- func GetConfigLoader(cfg any, opts ...Option) (*aconfig.Loader, error)
- func Load(cfg any, opts ...Option) error
- func LoadForTests(cfg any, opts ...Option) error
- func ValidateConfig(cfg any, opts ...Option) error
- type Config
- type ConfigField
- type Option
- type ValidateFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateYamlTemplate ¶
func GetConfigLoader ¶
GetConfigLoader returns aconfig loader instance.
func Load ¶
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 ¶
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 ¶
ValidateConfig validates config struct with environment variables and custom validation functions.
Types ¶
type ConfigField ¶
type ConfigField struct {
Path string
EnvName string
DefaultValue string
Usage string
Example string
ValidateParams string
IsRequired bool
IsSecret bool
DisableValidation bool
}
func GetConfigFields ¶
func GetConfigFields(loader *aconfig.Loader) []ConfigField
type Option ¶
type Option func(*options)
func WithContext ¶
func WithLoaderConfig ¶
WithEnvFile - path to dotenv config file.
func WithValidate ¶
func WithValidateFuncs ¶
func WithValidateFuncs(items ...ValidateFn) Option