Documentation
¶
Index ¶
- Constants
- func ClearTempDir()
- func CopyRef[T any](value T) *T
- func ElementType(initial reflect.Type) (et reflect.Type)
- func EnvironmentPreservesCase() bool
- func MustGetTempDir() string
- func NewUTF8Reader(reader io.ReadSeeker) io.Reader
- func NilOr[T comparable](value *T, expected T) bool
- func NotNilAnd[T comparable](value *T, expected T) bool
- func RegisterCharsetDecoder(fn DecoderFunc)
- func TempDir() (string, error)
- func UnpackValue(value reflect.Value) (v reflect.Value, isNil bool)
- type DecoderFunc
- type Environment
- func (e *Environment) Find(name string) (originalName, value string, ok bool)
- func (e *Environment) FoldedNames() (names []string)
- func (e *Environment) Get(name string) (value string)
- func (e *Environment) Has(name string) (found bool)
- func (e *Environment) Names() (names []string)
- func (e *Environment) Put(name, value string)
- func (e *Environment) Remove(name string)
- func (e *Environment) ResolveName(name string) string
- func (e *Environment) SetValues(values ...string)
- func (e *Environment) Values() (values []string)
- func (e *Environment) ValuesAsMap() (m map[string]string)
- type EnvironmentFile
Constants ¶
const MaxEnvironmentFileContentSize = 512 * 1024
MaxEnvironmentFileContentSize limits the max size of a single env file (to sanitize incorrect user input)
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 ElementType ¶
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 NewUTF8Reader ¶ added in v0.27.0
func NewUTF8Reader(reader io.ReadSeeker) io.Reader
NewUTF8Reader returns a reader that decodes the provided input to an UTF8 stream using registered DecoderFunc
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 RegisterCharsetDecoder ¶ added in v0.27.0
func RegisterCharsetDecoder(fn DecoderFunc)
RegisterCharsetDecoder allow to register a func that detects and decodes the charset of an arbitrary text stream
Types ¶
type DecoderFunc ¶ added in v0.27.0
type DecoderFunc func(reader io.ReadSeeker) transform.Transformer
DecoderFunc detects a charset and provides a transformer for it. May return nil when no charset was detected. The func is responsible for setting the reader's offset (e.g. rewind) before returning.
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
type EnvironmentFile ¶ added in v0.27.0
type EnvironmentFile struct {
// contains filtered or unexported fields
}
EnvironmentFile supports loading dotenv files
func GetEnvironmentFile ¶ added in v0.27.0
func GetEnvironmentFile(filename string) (env *EnvironmentFile, err error)
GetEnvironmentFile returns a pooled & immutable EnvironmentFile instance for the specified dotenv filename.
func (*EnvironmentFile) AddTo ¶ added in v0.27.0
func (f *EnvironmentFile) AddTo(e *Environment)
AddTo adds all environment values to the Environment instance
func (*EnvironmentFile) Name ¶ added in v0.27.0
func (f *EnvironmentFile) Name() string
Name returns the filename of the underlying dotenv file
func (*EnvironmentFile) Valid ¶ added in v0.27.0
func (f *EnvironmentFile) Valid() bool
Valid returns true as the loaded values are in-sync with underlying dotenv file
func (*EnvironmentFile) ValuesAsMap ¶ added in v0.27.0
func (f *EnvironmentFile) ValuesAsMap() map[string]string
ValuesAsMap returns all environment variables as name & value map