Categorygithub.com/smithy-security/pkg/env
modulepackage
0.0.1
Repository: https://github.com/smithy-security/pkg.git
Documentation: pkg.go.dev

# README

Env

Minimalistic package for environment variable lookup of type defined in Parseable.

Example usage

package main

import (
	"github.com/smithy-security/pkg/env"
)

func main() {
	// Will error if not defined or a valid integer.
	intVar, err := env.GetOrDefault("MY_INT_ENV_VAR", 10)
	if err != nil {
		...
    }

	// Will return the default value 10 if not defined or on error
	anotherIntVar, err := env.GetOrDefault("MY_OTHER_INT_ENV_VAR", 10, env.WithDefaultOnError(true))
	if err != nil {
		...
	}
}

On testing

Customise Loader to mock your environment. Check the examples in env_test.go.

# Functions

GetOrDefault attempts to parse the environment variable provided.
WithDefaultOnError informs the parser that if an error is encountered during parsing, it should fallback to the default value.
WithLoader allows overriding how env vars are loaded.

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author