envy

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

envy Go Version Go Reference Go

Type-safe environment variables parsing library for Go.

Installation

  go get github.com/0bl/envy

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get[V any](key string, parse func(string) (V, error), fallback ...V) (V, error)

Get retrieves an environment variable with parsing and fallback support.

func MustGet

func MustGet[V any](key string, parse func(string) (V, error)) V

MustGet retrieves an environment variable and panics if not found or parsed successfully.

func ParseString

func ParseString(val string) (string, error)

ParseString is a parsing function for string values.

func ParseStrings

func ParseStrings(val string) ([]string, error)

ParseStrings is a parsing function for slice of strings.

Types

type Envy

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

Envy is a configuration manager that retrieves environment variables with fallbacks.

func New

func New() *Envy

New creates a new instance of Envy with a default error handler that logs fatal errors.

func (*Envy) Bool

func (e *Envy) Bool(key string, fallback ...bool) bool

Bool retrieves an environment variable as a boolean.

func (*Envy) Duration

func (e *Envy) Duration(key string, fallback ...time.Duration) time.Duration

Duration retrieves an environment variable as a time.Duration.

func (*Envy) Int

func (e *Envy) Int(key string, fallback ...int) int

Int retrieves an environment variable as an integer.

func (*Envy) String

func (e *Envy) String(key string, fallback ...string) string

String retrieves an environment variable as a string.

func (*Envy) Strings

func (e *Envy) Strings(key string, fallback ...[]string) []string

Strings retrieves an environment variable as a slice of strings.

func (*Envy) WithErrorHandler

func (e *Envy) WithErrorHandler(errorHandler ErrorHandler) *Envy

WithErrorHandler sets a custom error handler for the Envy instance.

type ErrorHandler

type ErrorHandler = func(error)

ErrorHandler is a type for handling errors.

Jump to

Keyboard shortcuts

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