Documentation
¶
Overview ¶
Package config provides a centralized configuration management system for the Nexlayer CLI. It supports loading configuration from multiple sources (files, environment variables, flags) and provides a unified interface for accessing configuration values.
Package config provides a centralized configuration management system for the Nexlayer CLI. It supports loading configuration from multiple sources (files, environment variables, flags) and provides a unified interface for accessing configuration values.
Index ¶
- Constants
- Variables
- func GetAPIURL() string
- func GetConfigDir() (string, error)
- func GetDefaultNamespace() string
- func GetToken() string
- func InitConfig(configPath string) error
- func SaveConfig() error
- func SetAPIURL(url string)
- func SetDefaultManager(manager *Manager)
- func SetDefaultNamespace(namespace string)
- func SetToken(token string)
- func WithContext(ctx context.Context) context.Context
- type Manager
- func (m *Manager) GetAPIURL() string
- func (m *Manager) GetConfigDir() (string, error)
- func (m *Manager) GetDefaultNamespace() string
- func (m *Manager) GetToken() string
- func (m *Manager) InitConfig(configPath string) error
- func (m *Manager) Provider() Provider
- func (m *Manager) SaveConfig() error
- func (m *Manager) SetAPIURL(url string)
- func (m *Manager) SetDefaultNamespace(namespace string)
- func (m *Manager) SetToken(token string)
- func (m *Manager) WithContext(ctx context.Context) context.Context
- type Provider
- type ProviderKey
- type ViperProvider
- func (p *ViperProvider) AddConfigPath(path string)
- func (p *ViperProvider) AllSettings() map[string]interface{}
- func (p *ViperProvider) AutomaticEnv()
- func (p *ViperProvider) BindPFlag(key string, flag *pflag.Flag) error
- func (p *ViperProvider) ConfigFileUsed() string
- func (p *ViperProvider) Get(key string) interface{}
- func (p *ViperProvider) GetBool(key string) bool
- func (p *ViperProvider) GetDuration(key string) time.Duration
- func (p *ViperProvider) GetFloat64(key string) float64
- func (p *ViperProvider) GetInt(key string) int
- func (p *ViperProvider) GetString(key string) string
- func (p *ViperProvider) GetStringMap(key string) map[string]interface{}
- func (p *ViperProvider) GetStringMapString(key string) map[string]string
- func (p *ViperProvider) GetStringSlice(key string) []string
- func (p *ViperProvider) GetTime(key string) time.Time
- func (p *ViperProvider) IsSet(key string) bool
- func (p *ViperProvider) ReadInConfig() error
- func (p *ViperProvider) Set(key string, value interface{})
- func (p *ViperProvider) SetConfigFile(file string)
- func (p *ViperProvider) SetConfigName(name string)
- func (p *ViperProvider) SetConfigType(configType string)
- func (p *ViperProvider) SetDefault(key string, value interface{})
- func (p *ViperProvider) SetEnvPrefix(prefix string)
- func (p *ViperProvider) WriteConfig() error
Constants ¶
const DefaultConfigDir = ".config/nexlayer"
DefaultConfigDir is the default directory for the configuration file
const DefaultConfigName = "config"
DefaultConfigName is the default name for the configuration file
const DefaultConfigType = "yaml"
DefaultConfigType is the default type for the configuration file
Variables ¶
var DefaultProviderKey = ProviderKey{}
DefaultProviderKey is the default context key for the configuration provider
Functions ¶
func GetConfigDir ¶
GetConfigDir returns the directory where the configuration file is located
func GetDefaultNamespace ¶
func GetDefaultNamespace() string
GetDefaultNamespace returns the default namespace from the configuration
func GetToken ¶
func GetToken() string
GetToken returns the authentication token from the configuration
func InitConfig ¶
InitConfig initializes the configuration with default values and paths
func SetDefaultManager ¶
func SetDefaultManager(manager *Manager)
SetDefaultManager sets the default configuration manager
func SetDefaultNamespace ¶
func SetDefaultNamespace(namespace string)
SetDefaultNamespace sets the default namespace in the configuration
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles configuration loading and access
func DefaultManager ¶
func DefaultManager() *Manager
DefaultManager creates a new configuration manager with the default Viper provider
func GetDefaultManager ¶
func GetDefaultManager() *Manager
GetDefaultManager returns the default configuration manager
func NewManager ¶
NewManager creates a new configuration manager with the given provider
func (*Manager) GetConfigDir ¶
GetConfigDir returns the directory where the configuration file is located
func (*Manager) GetDefaultNamespace ¶
GetDefaultNamespace returns the default namespace from the configuration
func (*Manager) InitConfig ¶
InitConfig initializes the configuration with default values and paths
func (*Manager) SaveConfig ¶
SaveConfig saves the current configuration to disk
func (*Manager) SetDefaultNamespace ¶
SetDefaultNamespace sets the default namespace in the configuration
type Provider ¶
type Provider interface {
// Get retrieves a configuration value by key
Get(key string) interface{}
// GetString retrieves a string configuration value
GetString(key string) string
// GetInt retrieves an integer configuration value
GetInt(key string) int
// GetBool retrieves a boolean configuration value
GetBool(key string) bool
// GetFloat64 retrieves a float64 configuration value
GetFloat64(key string) float64
// GetTime retrieves a time.Time configuration value
GetTime(key string) time.Time
// GetDuration retrieves a time.Duration configuration value
GetDuration(key string) time.Duration
// GetStringSlice retrieves a string slice configuration value
GetStringSlice(key string) []string
// GetStringMap retrieves a map of string configuration values
GetStringMap(key string) map[string]interface{}
// GetStringMapString retrieves a map of string configuration values
GetStringMapString(key string) map[string]string
// IsSet checks if a configuration value is set
IsSet(key string) bool
// SetDefault sets a default value for a configuration key
SetDefault(key string, value interface{})
// Set sets a configuration value
Set(key string, value interface{})
// AllSettings returns all settings as a map
AllSettings() map[string]interface{}
// ConfigFileUsed returns the config file used for loading configuration
ConfigFileUsed() string
}
Provider defines the interface for accessing configuration values
func FromContext ¶
FromContext retrieves the configuration provider from the context
func GetConfigProvider ¶
func GetConfigProvider() Provider
GetConfigProvider returns the configuration provider
func MustFromContext ¶
MustFromContext retrieves the configuration provider from the context or panics
type ProviderKey ¶
type ProviderKey struct{}
ProviderKey is the context key for storing the configuration provider
type ViperProvider ¶
type ViperProvider struct {
// contains filtered or unexported fields
}
ViperProvider is a Provider implementation that uses Viper
func NewViperProvider ¶
func NewViperProvider() *ViperProvider
NewViperProvider creates a new ViperProvider
func (*ViperProvider) AddConfigPath ¶
func (p *ViperProvider) AddConfigPath(path string)
AddConfigPath adds a path for Viper to search for the config file in
func (*ViperProvider) AllSettings ¶
func (p *ViperProvider) AllSettings() map[string]interface{}
AllSettings returns all settings as a map
func (*ViperProvider) AutomaticEnv ¶
func (p *ViperProvider) AutomaticEnv()
AutomaticEnv tells Viper to check for environment variables
func (*ViperProvider) BindPFlag ¶
func (p *ViperProvider) BindPFlag(key string, flag *pflag.Flag) error
BindPFlag binds a flag to a configuration key
func (*ViperProvider) ConfigFileUsed ¶
func (p *ViperProvider) ConfigFileUsed() string
ConfigFileUsed returns the config file used for loading configuration
func (*ViperProvider) Get ¶
func (p *ViperProvider) Get(key string) interface{}
Get retrieves a configuration value by key
func (*ViperProvider) GetBool ¶
func (p *ViperProvider) GetBool(key string) bool
GetBool retrieves a boolean configuration value
func (*ViperProvider) GetDuration ¶
func (p *ViperProvider) GetDuration(key string) time.Duration
GetDuration retrieves a time.Duration configuration value
func (*ViperProvider) GetFloat64 ¶
func (p *ViperProvider) GetFloat64(key string) float64
GetFloat64 retrieves a float64 configuration value
func (*ViperProvider) GetInt ¶
func (p *ViperProvider) GetInt(key string) int
GetInt retrieves an integer configuration value
func (*ViperProvider) GetString ¶
func (p *ViperProvider) GetString(key string) string
GetString retrieves a string configuration value
func (*ViperProvider) GetStringMap ¶
func (p *ViperProvider) GetStringMap(key string) map[string]interface{}
GetStringMap retrieves a map of string configuration values
func (*ViperProvider) GetStringMapString ¶
func (p *ViperProvider) GetStringMapString(key string) map[string]string
GetStringMapString retrieves a map of string configuration values
func (*ViperProvider) GetStringSlice ¶
func (p *ViperProvider) GetStringSlice(key string) []string
GetStringSlice retrieves a string slice configuration value
func (*ViperProvider) GetTime ¶
func (p *ViperProvider) GetTime(key string) time.Time
GetTime retrieves a time.Time configuration value
func (*ViperProvider) IsSet ¶
func (p *ViperProvider) IsSet(key string) bool
IsSet checks if a configuration value is set
func (*ViperProvider) ReadInConfig ¶
func (p *ViperProvider) ReadInConfig() error
ReadInConfig reads in the config file
func (*ViperProvider) Set ¶
func (p *ViperProvider) Set(key string, value interface{})
Set sets a configuration value
func (*ViperProvider) SetConfigFile ¶
func (p *ViperProvider) SetConfigFile(file string)
SetConfigFile sets the config file explicitly
func (*ViperProvider) SetConfigName ¶
func (p *ViperProvider) SetConfigName(name string)
SetConfigName sets the name of the config file
func (*ViperProvider) SetConfigType ¶
func (p *ViperProvider) SetConfigType(configType string)
SetConfigType sets the type of the config file
func (*ViperProvider) SetDefault ¶
func (p *ViperProvider) SetDefault(key string, value interface{})
SetDefault sets a default value for a configuration key
func (*ViperProvider) SetEnvPrefix ¶
func (p *ViperProvider) SetEnvPrefix(prefix string)
SetEnvPrefix sets the prefix for environment variables
func (*ViperProvider) WriteConfig ¶
func (p *ViperProvider) WriteConfig() error
WriteConfig writes the current configuration to the config file