viperx

package
v0.9.2-beta.21 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: AGPL-3.0 Imports: 6 Imported by: 6

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

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 BindEnv

func BindEnv(input ...string) error

func BindPFlags

func BindPFlags(flags *pflag.FlagSet) error

func ConfigFileUsed

func ConfigFileUsed() string

func Get

func Get(key string) interface{}

func GetBool

func GetBool(key string) bool

func GetDuration

func GetDuration(key string) time.Duration

func GetFloat64 added in v0.7.4

func GetFloat64(key string) float64

func GetInt

func GetInt(key string) int

func GetInt32

func GetInt32(key string) int32

func GetString

func GetString(key string) string

func GetStringSlice

func GetStringSlice(key string) []string

func GetViper

func GetViper() *viper.Viper

func IsSet

func IsSet(key string) bool

func MergeConfigMap

func MergeConfigMap(cfg map[string]interface{}) error

func OnConfigChange

func OnConfigChange(run func(in fsnotify.Event))

func ReadInConfig

func ReadInConfig() error

func Reset

func Reset()

func Set

func Set(key string, value interface{})

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 SetEnvKeyReplacer(r *strings.Replacer)

func SetEnvPrefix

func SetEnvPrefix(in string)

func WatchConfig

func WatchConfig()

Types

This section is empty.

Jump to

Keyboard shortcuts

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