env

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetEnv added in v0.13.0

func GetEnv(s string) string

GetEnv is a helper function that retrieves a value from an environment variable independently if is has the env notation or not.

func HasEnvNotation added in v0.13.0

func HasEnvNotation(s string) bool

HasEnvNotation checks if a string has the mikros framework env notation indicating that it should be loaded from environment variables.

func Load

func Load(serviceName service.Name, env interface{}) error

Load loads environment variables directly into structures by using a special struct tag 'env'.

The 'env' tag allows defining the environment variable name that points to the struct member by using the tag first argument. It also allows setting a default value, with the attribute 'default_value', for variables that are not found, and an attribute 'skip' to skip members of being loaded.

The function also receives the service name as argument so it can search for environment variables specific to the own service, and to be one specific to the service, the environment variable must end (have as suffix) a dot '.' followed by the service name. Like:

FOO => global variable, for all services
FOO.bar => variable only for service 'bar'

Types

type Env

type Env[T any] struct {
	// contains filtered or unexported fields
}

Env is a type that holds information about a single environment variable. It can give both the environment variable source name and its loaded value.

func (Env[T]) String

func (e Env[T]) String() string

func (Env[T]) Value

func (e Env[T]) Value() T

func (Env[T]) VarName

func (e Env[T]) VarName() string

Jump to

Keyboard shortcuts

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