loaderenv

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) loader.Loader

Types

type Loader

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

func (Loader) Load added in v0.4.0

func (l Loader) Load(ctx context.Context, to any, opt *loader.Option) error

Load loads the configuration from the environment.

  • to must be a pointer to a struct
  • only struct fields load values

func (*Loader) LoadName added in v0.4.0

func (l *Loader) LoadName() loader.LoaderName

func (*Loader) LoadOrder added in v0.4.0

func (l *Loader) LoadOrder() loader.Order

type Option

type Option func(*option)

func WithCheckConfigEnvFile added in v0.4.0

func WithCheckConfigEnvFile(check bool) Option

WithCheckConfigEnvFile enables checking CONFIG_ENV_FILE variable to load specific environment file.

  • if true and CONFIG_ENV_FILE is set, the file is appended to the list of env files to load.
  • default is true.

func WithEnv

func WithEnv(env map[string]string) Option

WithEnv sets the environment variables to load and disable from the system environment.

func WithEnvFile

func WithEnvFile(path ...string) Option

func WithHooks

func WithHooks(hooks ...loader.HookFunc) Option

WithHooks sets the hooks for the environment loader.

  • if return type matches the field type, return value is assigned to the field

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix to just load the environment variables with the given prefix.

  • if prefix is "APP_", then only the environment variables with the prefix "APP_" are loaded.
  • prefix will strip from the field name.

func WithTag

func WithTag(tag string) Option

WithTag is `cfg` by default.

  • tag is used if `env“ tag is not found.

func WithTagEnv

func WithTagEnv(tagName string) Option

WithTagEnv is `env` by default.

Jump to

Keyboard shortcuts

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