Env

The Env registry provides functions for accessing and managing environment variables, enabling dynamic configuration of your applications based on the runtime environment.

circle-info

You can easily import all the functions from the env registry by including the following import statement in your code

import "github.com/go-sprout/sprout/registry/env"

env

The function retrieves the value of a specified environment variable from the system.

Signature

Env(key string) string

Must version

{{ env "INVALID" }} // Output: ""
{{ "PATH" | env }} // Output: "/usr/bin:/bin:/usr/sbin:/sbin"

expandEnv

The function replaces occurrences of ${var} or $var in a string with the corresponding values from the current environment variables.

Signature

ExpandEnv(str string) string

Must version

{{ "Path is $PATH" | expandEnv }} // Output: "Path is /usr/bin:/bin:/usr/sbin:/sbin"

Last updated