env

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: Apache-2.0 Imports: 24 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActiveProfiles

func ActiveProfiles() []string

last wins

func ConfigurationProperties

func ConfigurationProperties[T any](prefix string, target *T) *T

func MatchesProfiles added in v1.0.9

func MatchesProfiles(profiles ...string) bool

Determine whether one or more of the given profiles is active.

If a profile begins with '!' the logic is inverted, meaning this method will return true if the given profile is not active. For example, env.MatchesProfiles("p1", "!p2") will return true if profile 'p1' is active or 'p2' is not active. A compound expression allows for more complicated profile logic to be expressed, for example "production & cloud".

func SetActiveProfiles

func SetActiveProfiles(profiles string)

Bootstrap new environment with profiles listed, last wins. Do nothing if very profiles are already set in the specified order. Reload environment if empty value provided

func Value

func Value[T any](expression string) T

Expression to evaluate against environment properties

require.Equal(t, "value", env.Value[string]("${key:default}"))
require.Equal(t, []string{"host1", "host2", "host3"}, env.Value[[]string]("#{split('${servers}', ',')}"))

Types

type Base64PropertySource

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

custom property source as additional logic for properties processing, like property=base64:dGVzdAo=

func NewBase64PropertySource

func NewBase64PropertySource(environment *Environment) *Base64PropertySource

func (*Base64PropertySource) HasProperty

func (s *Base64PropertySource) HasProperty(key string) bool

func (*Base64PropertySource) Name

func (s *Base64PropertySource) Name() string

func (*Base64PropertySource) Properties

func (s *Base64PropertySource) Properties() map[string]string

func (*Base64PropertySource) Property

func (s *Base64PropertySource) Property(key string) string

type Environment

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

func Instance

func Instance() *Environment

func (*Environment) ActiveProfiles

func (e *Environment) ActiveProfiles() []string

last wins

func (*Environment) AddPropertySource

func (e *Environment) AddPropertySource(source PropertySource)

custom property source as additional logic for properties processing, like property=base64:dGVzdAo=, see Base64PropertySource as an example

env.Instance().AddPropertySource(env.NewBase64PropertySource(env.Instance()))

func (*Environment) MatchesProfiles

func (e *Environment) MatchesProfiles(profiles ...string) bool

Determine whether one or more of the given profiles is active.

If a profile begins with '!' the logic is inverted, meaning this method will return true if the given profile is not active. For example, env.MatchesProfiles("p1", "!p2") will return true if profile 'p1' is active or 'p2' is not active. A compound expression allows for more complicated profile logic to be expressed, for example "production & cloud".

func (*Environment) Property

func (e *Environment) Property(key string) any

func (*Environment) PropertySources

func (e *Environment) PropertySources() []PropertySource

first wins

func (*Environment) ResolveRequiredPlaceholders

func (e *Environment) ResolveRequiredPlaceholders(expression string) any

type ExprProcessor

type ExprProcessor struct {
	text.PatternProcessor
	// contains filtered or unexported fields
}

func ExprProcessorOf

func ExprProcessorOf(strict bool) *ExprProcessor

func (*ExprProcessor) Define

func (p *ExprProcessor) Define(key string, value any)

func (*ExprProcessor) Reset

func (p *ExprProcessor) Reset()

func (*ExprProcessor) Resolve

func (p *ExprProcessor) Resolve(match *regex.Match,
	super func(*regex.Match) any) (resolved any)

func (*ExprProcessor) SetStrict

func (p *ExprProcessor) SetStrict(strict bool)

type MapPropertySource

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

func MapPropertySourceOf

func MapPropertySourceOf(name string) *MapPropertySource

func MapPropertySourceOfMap

func MapPropertySourceOfMap(name string, source map[string]string) *MapPropertySource

func (*MapPropertySource) ContainsProperty

func (s *MapPropertySource) ContainsProperty(key string) bool

func (*MapPropertySource) HasProperty

func (s *MapPropertySource) HasProperty(key string) bool

func (*MapPropertySource) Name

func (s *MapPropertySource) Name() string

func (*MapPropertySource) Properties

func (s *MapPropertySource) Properties() map[string]string

func (*MapPropertySource) Property

func (s *MapPropertySource) Property(key string) string

func (*MapPropertySource) SetProperties

func (s *MapPropertySource) SetProperties(properties map[string]string)

func (*MapPropertySource) SetProperty

func (s *MapPropertySource) SetProperty(key string, value string)

type PropertiesPropertySource

type PropertiesPropertySource struct {
	MapPropertySource
}

func NewPropertiesPropertySource

func NewPropertiesPropertySource(name, content string) *PropertiesPropertySource

type PropertySource

type PropertySource interface {
	Name() string
	HasProperty(key string) bool
	Property(key string) string
	Properties() map[string]string
}

type YamlPropertySource

type YamlPropertySource struct {
	MapPropertySource
}

func NewYamlPropertySource

func NewYamlPropertySource(name, yaml string) *YamlPropertySource

Jump to

Keyboard shortcuts

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