Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsProjectStorageConfig ¶
IsProjectStorageConfig returns true if the key starts with the prefix "storage.project.".
func IsUserConfig ¶
IsUserConfig returns true if the key starts with the prefix "user.".
Types ¶
type DaemonStorageType ¶
type DaemonStorageType string
DaemonStorageType represents the type of storage volume configurable in the daemon config.
const ( DaemonStorageTypeImages DaemonStorageType = "images" DaemonStorageTypeBackups DaemonStorageType = "backups" )
Define the possible types of daemon storage.
func ParseDaemonStorageConfigKey ¶
func ParseDaemonStorageConfigKey(config string) (projectName string, storageType DaemonStorageType)
ParseDaemonStorageConfigKey parses a daemon storage config key and returns the project name and the type of storage it refers to. It supports both project-specific keys (e.g., "storage.project.<name>.images_volume") and daemon storage keys (e.g., "storage.images_volume"). If the key is not recognized, it returns an empty string and an empty DaemonStorageType.
type Error ¶
type Error struct {
Name string // The name of the key this error is associated with.
Value any // The value that the key was tried to be set to.
Reason string // Human-readable reason of the error.
}
Error generated when trying to set a certain config key to certain value.
type ErrorList ¶
type ErrorList []*Error
ErrorList is a list of configuration Errors occurred during Load() or Map.Change().
type Key ¶
type Key struct {
Type Type // Type of the value. It defaults to String.
Default string // If the key is not set in a Map, use this value instead.
Deprecated string // Optional message to set if this config value is deprecated.
// Optional function used to validate the values. It's called by Map
// all the times the value associated with this Key is going to be
// changed.
Validator func(string) error
// Optional function to manipulate a value before it's actually saved
// in a Map. It's called only by Map.Change(), and not by Load() since
// values passed to Load() are supposed to have been previously
// processed.
Setter func(string) (string, error)
}
Key defines the type of the value of a particular config key, along with other knobs such as default, validator, etc.
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map is a structured map of config keys to config values.
Each legal key is declared in a config Schema using a Key object.
func Load ¶
Load creates a new configuration Map with the given schema and initial values. It is meant to be called with a set of initial values that were set at a previous time and persisted to some storage like a database.
If one or more keys fail to be loaded, return an ErrorList describing what went wrong. Non-failing keys are still loaded in the returned Map.
func SafeLoad ¶
SafeLoad is a wrapper around Load() that does not error when invalid keys are found, and just logs warnings instead. Other kinds of errors are still returned.
func (*Map) Change ¶
Change the values of this configuration Map.
Return a map of key/value pairs that were actually changed. If some keys fail to apply, details are included in the returned ErrorList.
func (*Map) Dump ¶
Dump the current configuration held by this Map. Keys that match their default value will not be included in the dump.