envutil

package
v0.23.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearEnvCache

func ClearEnvCache()

ClearEnvCache clears saved environment values so that a new read access the environment again. (Used for testing)

func EnvOrDefaultBool

func EnvOrDefaultBool(name string, value bool) bool

EnvOrDefaultBool returns the value set by the specified environment variable, if any, otherwise the specified default value.

N.B. EnvOrDefaultBool has the desired side-effect of populating envVarRegistry.cache. It has to be invoked during (var) init; otherwise, cli/start.go:reportConfiguration will not report the value of this environment variable in the server log, upon startup.

Correct Usage: var allowUpgradeToDev = envutil.EnvOrDefaultBool("COCKROACH_UPGRADE_TO_DEV_VERSION", false)

Incorrect Usage: func() {
										...
										var allowUpgradeToDev envutil.EnvOrDefaultBool("COCKROACH_UPGRADE_TO_DEV_VERSION", false)
									}

N.B. The same rule applies to the remaining EnvOrDefaultXXX defined here.

func EnvOrDefaultBytes

func EnvOrDefaultBytes(name string, value int64) int64

EnvOrDefaultBytes returns the value set by the specified environment variable, if any, otherwise the specified default value.

func EnvOrDefaultDuration

func EnvOrDefaultDuration(name string, value time.Duration) time.Duration

EnvOrDefaultDuration returns the value set by the specified environment variable, if any, otherwise the specified default value.

func EnvOrDefaultFloat64

func EnvOrDefaultFloat64(name string, value float64) float64

EnvOrDefaultFloat64 returns the value set by the specified environment variable, if any, otherwise the specified default value.

func EnvOrDefaultInt

func EnvOrDefaultInt(name string, value int) int

EnvOrDefaultInt returns the value set by the specified environment variable, if any, otherwise the specified default value.

func EnvOrDefaultInt64

func EnvOrDefaultInt64(name string, value int64) int64

EnvOrDefaultInt64 returns the value set by the specified environment variable, if any, otherwise the specified default value.

func EnvOrDefaultString

func EnvOrDefaultString(name string, value string) string

EnvOrDefaultString returns the value set by the specified environment variable, if any, otherwise the specified default value.

func EnvString

func EnvString(name string, depth int) (string, bool)

EnvString returns the value set by the specified environment variable. The depth argument indicates the stack depth of the caller that should be associated with the variable. The returned boolean flag indicates if the variable is set.

func ExternalEnvString

func ExternalEnvString(name string, depth int) (string, bool)

ExternalEnvString returns the value set by the specified environment variable. Only non-CRDB environment variables should be accessed via this method. CRDB specific variables should be accessed via EnvString. The depth argument indicates the stack depth of the caller that should be associated with the variable. The returned boolean flag indicates if the variable is set.

func GetEnvReport

func GetEnvReport() string

GetEnvReport dumps all configuration variables that may have been used and their value.

func GetEnvVarsUsed

func GetEnvVarsUsed() (result []redact.RedactableString)

GetEnvVarsUsed returns the names of all environment variables that may have been used.

func GetShellCommand

func GetShellCommand(cmd string) []string

GetShellCommand returns a complete command to run with a prefix of the command line.

func HomeDir

func HomeDir() (string, error)

HomeDir returns the user's home directory, as determined by the env var HOME, if it exists, and otherwise the system's idea of the user configuration (e.g. on non-UNIX systems).

func TestSetEnv

func TestSetEnv(t TB, name string, value string) func()

TestSetEnv sets an environment variable and the cleanup function resets it to the original value.

func TestUnsetEnv

func TestUnsetEnv(t TB, name string) func()

TestUnsetEnv unsets an environment variable and the cleanup function resets it to the original value.

Types

type TB

type TB interface {
	Fatal(args ...interface{})
	Helper()
}

TB is a slimmed down version of testing.T for use below. We would like to use testutils.TB but this is not possible due to a dependency cycle.

Jump to

Keyboard shortcuts

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