envloader

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Loader

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

func New

func New(opts ...Option) *Loader

func (Loader) Load

func (l Loader) Load(ctx context.Context, to any) error

Load loads the configuration from the environment.

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

func (Loader) LoadChu

func (l Loader) LoadChu(ctx context.Context, to any, opts ...loader.Option) error

type Option

type Option func(*option)

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