env

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2024 License: MIT Imports: 7 Imported by: 0

README

env

environment config loader

Initialize a struct from the process environment.

type Example struct {
    NumItems    int             `env:"PROC_NUM_ITEMS,33"`                   // With a default value of 33
    KeyName     string          `env:"PROC_KEY_NAME"`                       // With no default
    EnableThing bool            `env:"PROC_ENABLE_THING,f"`                 // Accepts true,t,1 for true and false,f,0 for false
    Duration    time.Duration   `env:"PROC_DUR_SOMETHING,10s,duration"`     // Treats inputs as durations
    Names       []string        `env:"PROC_NAMES,systemd;sshd;hello world"  // Slice (strings only)
    NamesSet    map[string]any  `env:"PROC_NAMES_SET,systemd;sshd"          // Map of strings as keys
}

config := &Example{}
err := env.Initialize(config)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initialize

func Initialize(target any) error

Initialize initializes target from the environment

func ParseDuration added in v0.0.2

func ParseDuration(value string) (time.Duration, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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