config

package
v0.0.0-...-41767dd Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const EnvVarPrefix = "ACTIVESTATE_CONFIG_"

EnvVarPrefix is prepended to a config key to derive its canonical environment-variable override.

Variables

View Source
var EmptyEvent = func(value interface{}) (interface{}, error) {
	if enum, ok := value.(*Enums); ok {

		return enum.Default, nil
	}
	return value, nil
}

Functions

func AddListener

func AddListener(key string, callback func())

AddListener adds a listener for changes to the given config key that calls the given callback function. Client code is responsible for calling NotifyListeners to signal config changes to listeners.

func CanonicalEnvVarName

func CanonicalEnvVarName(key string) string

CanonicalEnvVarName returns the environment variable that overrides the given config key. Every registered config option can be overridden this way, e.g. "api.host" maps to "ACTIVESTATE_CONFIG_API_HOST".

func EnvOverride

func EnvOverride(opt Option) (interface{}, string, bool)

EnvOverride returns the effective override value for the option when one of its environment variables is currently set to a non-empty, valid value, coerced to the option's type. The second return value is the name of the variable in effect; the bool reports whether an override applies.

A variable whose value cannot be strictly coerced to the option's type (an unparseable bool/int or an enum value outside the allowed set) is ignored, so a mis-typed variable falls back to the stored/default value rather than silently changing behavior to a zero value.

func EnvVarNames

func EnvVarNames(opt Option) []string

EnvVarNames returns every environment variable that can override this option: its canonical ACTIVESTATE_CONFIG_* variable first, followed by any legacy aliases.

func GetDefault

func GetDefault(opt Option) interface{}

func KnownOption

func KnownOption(rule Option) bool

func NotifyListeners

func NotifyListeners(key string)

NotifyListeners notifies listeners that the given config key has changed.

func RegisterHiddenOption

func RegisterHiddenOption(key string, t Type, defaultValue interface{})

Registers a hidden config option without get/set events.

func RegisterOption

func RegisterOption(key string, t Type, defaultValue interface{}, envAliases ...string)

RegisterOption registers a config option without get/set events. Any envAliases are additional legacy/bespoke environment variables that override the option, in addition to its canonical ACTIVESTATE_CONFIG_* variable. They exist only for env vars that predate and do not use the canonical prefix (e.g. ACTIVESTATE_API_HOST).

func RegisterOptionWithEvents

func RegisterOptionWithEvents(key string, t Type, defaultValue interface{}, get, set Event)

Registers a config option with get/set events.

Types

type Enums

type Enums struct {
	Options []string
	Default string
}

func NewEnum

func NewEnum(options []string, default_ string) *Enums

type Event

type Event func(value interface{}) (interface{}, error)

Event is run when a user tries to set or get a config value via `state config`

type Option

type Option struct {
	Name    string
	Type    Type
	Default interface{}
	// EnvAliases are additional (legacy/bespoke) environment variables that override this option, in
	// addition to its canonical CanonicalEnvVarName. They are kept for backwards compatibility with
	// env vars that predate the canonical ACTIVESTATE_CONFIG_* scheme (e.g. ACTIVESTATE_API_HOST).
	EnvAliases []string
	GetEvent   Event
	SetEvent   Event
	// contains filtered or unexported fields
}

Option defines what a config value's name and type should be, along with any get/set events

func GetOption

func GetOption(key string) Option

GetOption returns a config option, regardless of whether or not it has been registered. Use KnownOption to determine if the returned option has been previously registered.

func Registered

func Registered() []Option

Registered returns all registered options, excluding hidden ones

type Registry

type Registry map[string]Option

type Type

type Type int
const (
	String Type = iota
	Int
	Bool
	Enum
)

Jump to

Keyboard shortcuts

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