Env

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

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
{{ 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
{{ "Path is $PATH" | expandEnv }} // Output: "Path is /usr/bin:/bin:/usr/sbin:/sbin"

Last updated

Change request #24: reflect safe functions feature and new signatures