Documentation ¶
Overview ¶
Package viperx is a thread-safe extension for the Viper configuration library.
Overview ¶
The viperx package provides a set of utilities and enhancements to the Viper library that ensure thread-safety when working with configuration settings in concurrent environments.
Features ¶
Thread-safe access: All operations on the configuration settings are designed to be safe for concurrent access from multiple goroutines.
Locking mechanism: The package utilizes a mutex lock to protect concurrent read and write operations on the underlying Viper configuration.
Usage ¶
To use viperx, import the package and call viperx.XXX where supposed to call viper.XXX. Or, import the package and set the alias to viper, all viper calls exist should work well.
Example:
import "github.com/apecloud/kubeblocks/pkg/viperx" func main() { // Set a configuration value viperx.Set("key", "value") // Get a configuration value val := viperx.Get("key") fmt.Println(val) }
Note: While ViperX ensures thread-safety for the configuration settings, it does not modify the underlying behavior of Viper itself. It is still important to follow the guidelines and best practices provided by Viper for configuration management.
For more information on Viper, refer to the official Viper documentation at: https://github.com/spf13/viper
Index ¶
- func AddConfigPath(in string)
- func AllSettings() map[string]interface{}
- func AutomaticEnv()
- func BindEnv(input ...string) error
- func BindPFlags(flags *pflag.FlagSet) error
- func ConfigFileUsed() string
- func Get(key string) interface{}
- func GetBool(key string) bool
- func GetDuration(key string) time.Duration
- func GetFloat64(key string) float64
- func GetInt(key string) int
- func GetInt32(key string) int32
- func GetString(key string) string
- func GetStringSlice(key string) []string
- func GetViper() *viper.Viper
- func IsSet(key string) bool
- func MergeConfigMap(cfg map[string]interface{}) error
- func OnConfigChange(run func(in fsnotify.Event))
- func ReadInConfig() error
- func Reset()
- func Set(key string, value interface{})
- func SetConfigFile(in string)
- func SetConfigName(in string)
- func SetConfigType(in string)
- func SetDefault(key string, value interface{})
- func SetEnvKeyReplacer(r *strings.Replacer)
- func SetEnvPrefix(in string)
- func WatchConfig()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddConfigPath ¶
func AddConfigPath(in string)
func AllSettings ¶
func AllSettings() map[string]interface{}
func AutomaticEnv ¶
func AutomaticEnv()
func BindPFlags ¶
func ConfigFileUsed ¶
func ConfigFileUsed() string
func GetDuration ¶
func GetFloat64 ¶ added in v0.7.4
func GetStringSlice ¶
func MergeConfigMap ¶
func OnConfigChange ¶
func ReadInConfig ¶
func ReadInConfig() error
func SetConfigFile ¶
func SetConfigFile(in string)
func SetConfigName ¶
func SetConfigName(in string)
func SetConfigType ¶
func SetConfigType(in string)
func SetDefault ¶
func SetDefault(key string, value interface{})
func SetEnvKeyReplacer ¶
func SetEnvPrefix ¶
func SetEnvPrefix(in string)
func WatchConfig ¶
func WatchConfig()
Types ¶
This section is empty.