util

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearTempDir

func ClearTempDir()

ClearTempDir removes the temporary directory (if present) and resets the state. This is not safe for concurrent use and is meant for cleanup in unit tests only.

func CopyRef

func CopyRef[T any](value T) *T

CopyRef returns a pointer to a copy of value

func ElementType

func ElementType(initial reflect.Type) (et reflect.Type)

ElementType returns the type after removing all reflect.Array, reflect.Chan, reflect.Map, reflect.Pointer and reflect.Slice

func EnvironmentPreservesCase added in v0.23.0

func EnvironmentPreservesCase() bool

EnvironmentPreservesCase returns true if environment variables are case sensitive (all OS except Windows)

func MustGetTempDir

func MustGetTempDir() string

MustGetTempDir returns the dir from TempDir or panics if an error occurred

func NilOr

func NilOr[T comparable](value *T, expected T) bool

NilOr returns true if value is nil or expected

func NotNilAnd

func NotNilAnd[T comparable](value *T, expected T) bool

NotNilAnd returns true if value is not nil and expected

func TempDir

func TempDir() (string, error)

TempDir returns the path to a temporary directory that is stable within the same process and cleaned when shutdown.RunHooks is invoked

func UnpackValue

func UnpackValue(value reflect.Value) (v reflect.Value, isNil bool)

UnpackValue dereferences reflect.Pointer and reflect.Interface values

Types

type Environment added in v0.23.0

type Environment struct {
	// contains filtered or unexported fields
}

Environment manages a set of environment variables

func NewDefaultEnvironment added in v0.23.0

func NewDefaultEnvironment(values ...string) *Environment

NewDefaultEnvironment creates Environment with OS defaults for preserveCase and the specified initial values

func NewEnvironment added in v0.23.0

func NewEnvironment(preserveCase bool, values ...string) *Environment

NewEnvironment creates Environment with optional preserveCase and the specified initial values

func NewFoldingEnvironment added in v0.23.0

func NewFoldingEnvironment(values ...string) *Environment

NewFoldingEnvironment creates an Environment that folds the case of variable names

func (*Environment) Find added in v0.23.0

func (e *Environment) Find(name string) (originalName, value string, ok bool)

Find returns the variable's original name, its value and ok when the variable exists

func (*Environment) FoldedNames added in v0.23.0

func (e *Environment) FoldedNames() (names []string)

FoldedNames returns all environment variables names (case depends on preserveCase)

func (*Environment) Get added in v0.23.0

func (e *Environment) Get(name string) (value string)

Get returns the variable value, possibly an empty string when the variable is unset or empty.

func (*Environment) Has added in v0.23.0

func (e *Environment) Has(name string) (found bool)

Has returns true as the variable with name is set.

func (*Environment) Names added in v0.23.0

func (e *Environment) Names() (names []string)

Names returns all environment variables names (case is preserved as inserted)

func (*Environment) Put added in v0.23.0

func (e *Environment) Put(name, value string)

Put sets a single name and value pair

func (*Environment) Remove added in v0.23.0

func (e *Environment) Remove(name string)

Remove deletes the named env variable

func (*Environment) ResolveName added in v0.23.0

func (e *Environment) ResolveName(name string) string

ResolveName resolves the specified name to the actual variable name if case folding applies (preserveCase is false)

func (*Environment) SetValues added in v0.23.0

func (e *Environment) SetValues(values ...string)

SetValues sets one or more values of the format NAME=VALUE

func (*Environment) Values added in v0.23.0

func (e *Environment) Values() (values []string)

Values returns all environment variables as NAME=VALUE lines (case is preserved as inserted)

func (*Environment) ValuesAsMap added in v0.23.0

func (e *Environment) ValuesAsMap() (m map[string]string)

ValuesAsMap returns all environment variables as name & value map

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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