### Install Viper Package Source: https://pkg.go.dev/github.com/spf13/viper Use the go get command to add the Viper dependency to your Go project. ```bash go get github.com/spf13/viper ``` -------------------------------- ### Viper Registry Structure and Examples Source: https://pkg.go.dev/github.com/spf13/viper The core Viper struct and examples of how configuration priority is resolved. ```go type Viper struct { // contains filtered or unexported fields } ``` ```go Defaults : { "secret": "", "user": "default", "endpoint": "https://localhost" } Config : { "user": "root" "secret": "defaultsecret" } Env : { "secret": "somesecretkey" } ``` ```go { "secret": "somesecretkey", "user": "root", "endpoint": "https://localhost" } ``` -------------------------------- ### Get Config File Used Source: https://pkg.go.dev/github.com/spf13/viper Returns the name of the configuration file that was used to populate the configuration registry. ```go func ConfigFileUsed() string ``` -------------------------------- ### Watch Remote Configuration Source Source: https://pkg.go.dev/github.com/spf13/viper Starts watching the remote configuration source for changes. This function returns an error if the watching process fails. ```go func WatchRemoteConfig() error ``` -------------------------------- ### Watch Configuration File for Changes Source: https://pkg.go.dev/github.com/spf13/viper Starts watching the configured configuration file for any modifications. When changes are detected, Viper can be reloaded. ```go func WatchConfig() ``` -------------------------------- ### Watch Remote Configuration Source: https://pkg.go.dev/github.com/spf13/viper Starts watching remote configuration sources for changes. ```APIDOC ## WatchRemoteConfig ### Description Starts watching remote configuration sources for changes. ### Method `WatchRemoteConfig` ### Returns - **error** - An error if watching fails. ``` -------------------------------- ### Manage Remote Config with Crypt Source: https://pkg.go.dev/github.com/spf13/viper Commands to install the crypt utility and set or retrieve configuration values from a remote store. ```bash $ go get github.com/sagikazarmark/crypt/bin/crypt $ crypt set -plaintext /config/hugo.json /Users/hugo/settings/config.json ``` ```bash $ crypt get -plaintext /config/hugo.json ``` -------------------------------- ### Access Nested Configuration Keys Source: https://pkg.go.dev/github.com/spf13/viper Examples of accessing nested fields and array indices using dot-delimited paths. ```json { "host": { "address": "localhost", "port": 5799 }, "datastore": { "metric": { "host": "127.0.0.1", "port": 3099 }, "warehouse": { "host": "198.0.0.1", "port": 2112 } } } ``` ```go GetString("datastore.metric.host") // (returns "127.0.0.1") ``` ```json { "host": { "address": "localhost", "ports": [ 5799, 6029 ] }, "datastore": { "metric": { "host": "127.0.0.1", "port": 3099 }, "warehouse": { "host": "198.0.0.1", "port": 2112 } } } ``` ```go GetInt("host.ports.1") // returns 6029 ``` ```json { "datastore.metric.host": "0.0.0.0", "host": { "address": "localhost", "port": 5799 }, "datastore": { "metric": { "host": "127.0.0.1", "port": 3099 }, "warehouse": { "host": "198.0.0.1", "port": 2112 } } } ``` ```go GetString("datastore.metric.host") // returns "0.0.0.0" ``` -------------------------------- ### Get Environment Prefix Source: https://pkg.go.dev/github.com/spf13/viper Retrieves the configured environment variable prefix used by Viper. ```go func GetEnvPrefix() string ``` -------------------------------- ### Watch Remote Configuration on Channel Source: https://pkg.go.dev/github.com/spf13/viper Starts watching remote configuration sources for changes and sends updates to a channel. ```APIDOC ## WatchRemoteConfigOnChannel ### Description Starts watching remote configuration sources for changes and sends updates to a channel. ### Method `WatchRemoteConfigOnChannel` ### Returns - **error** - An error if watching fails. ``` -------------------------------- ### Get Sub Configuration Source: https://pkg.go.dev/github.com/spf13/viper Returns a sub-Viper for a given key, allowing hierarchical configuration management. ```APIDOC ## Sub ### Description Returns a sub-Viper for a given key. ### Method `Sub` ### Parameters - **key** (string) - Required - The key for the sub-configuration. ### Returns - **(*Viper)** - A sub-Viper instance. ``` -------------------------------- ### Watch Configuration Changes Source: https://pkg.go.dev/github.com/spf13/viper Starts watching the configuration file for changes and automatically reloads the configuration. ```APIDOC ## WatchConfig ### Description Starts watching a config file for changes. ### Method `WatchConfig` ### Returns - **None** ``` -------------------------------- ### Set Environment Variable Prefix Source: https://pkg.go.dev/github.com/spf13/viper Defines a prefix for environment variables. Viper will look for environment variables starting with this prefix, followed by an underscore. For example, with a prefix 'spf', it will look for 'SPF_'. ```go func SetEnvPrefix(in string) ``` -------------------------------- ### Viper Initialization Source: https://pkg.go.dev/github.com/spf13/viper Methods for creating and retrieving Viper configuration instances. ```APIDOC ## New ### Description Returns an initialized Viper instance. ## GetViper ### Description Gets the global Viper instance. ## NewWithOptions ### Description Creates a new Viper instance with functional options. ### Parameters #### Request Body - **opts** (...Option) - Optional - Functional options to configure the Viper instance. ``` -------------------------------- ### Establish Configuration Defaults Source: https://pkg.go.dev/github.com/spf13/viper Set default values for configuration keys that are used if no other source provides a value. ```go viper.SetDefault("ContentDir", "content") viper.SetDefault("LayoutDir", "layouts") viper.SetDefault("Taxonomies", map[string]string{"tag": "tags", "category": "categories"}) ``` -------------------------------- ### Get Source: https://pkg.go.dev/github.com/spf13/viper Retrieves a value for a given key. ```APIDOC ## Get ### Description Retrieves any value given the key. Get is case-insensitive. Viper checks in order: override, flag, env, config file, key/value store, default. ### Parameters - **key** (string) - Required - The configuration key to retrieve. ``` -------------------------------- ### Retrieve All Settings Source: https://pkg.go.dev/github.com/spf13/viper Merges all configuration settings from various sources and returns them as a map[string]any. ```go func AllSettings() map[string]any ``` -------------------------------- ### Get Configuration Values Source: https://pkg.go.dev/github.com/spf13/viper Functions to retrieve configuration values as specific data types. ```APIDOC ## GetInt32 ### Description GetInt32 returns the value associated with the key as an integer. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** (int32) - The integer value associated with the key. #### Response Example ```json { "value": 123 } ``` ``` ```APIDOC ## GetInt64 ### Description GetInt64 returns the value associated with the key as an integer. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** (int64) - The integer value associated with the key. #### Response Example ```json { "value": 456 } ``` ``` ```APIDOC ## GetIntSlice ### Description GetIntSlice returns the value associated with the key as a slice of int values. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** ([]int) - The slice of integers associated with the key. #### Response Example ```json { "value": [1, 2, 3] } ``` ``` ```APIDOC ## GetSizeInBytes ### Description GetSizeInBytes returns the size of the value associated with the given key in bytes. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **size** (uint) - The size of the value in bytes. #### Response Example ```json { "size": 1024 } ``` ``` ```APIDOC ## GetString ### Description GetString returns the value associated with the key as a string. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** (string) - The string value associated with the key. #### Response Example ```json { "value": "example string" } ``` ``` ```APIDOC ## GetStringMap ### Description GetStringMap returns the value associated with the key as a map of interfaces. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** (map[string]any) - The map of interfaces associated with the key. #### Response Example ```json { "value": { "key1": "value1", "key2": 123 } } ``` ``` ```APIDOC ## GetStringMapString ### Description GetStringMapString returns the value associated with the key as a map of strings. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** (map[string]string) - The map of strings associated with the key. #### Response Example ```json { "value": { "key1": "value1", "key2": "value2" } } ``` ``` ```APIDOC ## GetStringMapStringSlice ### Description GetStringMapStringSlice returns the value associated with the key as a map to a slice of strings. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** (map[string][]string) - The map to a slice of strings associated with the key. #### Response Example ```json { "value": { "key1": ["val1a", "val1b"], "key2": ["val2a"] } } ``` ``` ```APIDOC ## GetStringSlice ### Description GetStringSlice returns the value associated with the key as a slice of strings. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** ([]string) - The slice of strings associated with the key. #### Response Example ```json { "value": ["string1", "string2"] } ``` ``` ```APIDOC ## GetTime ### Description GetTime returns the value associated with the key as time.Time. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** (time.Time) - The time value associated with the key. #### Response Example ```json { "value": "2023-10-27T10:00:00Z" } ``` ``` ```APIDOC ## GetUint ### Description GetUint returns the value associated with the key as an unsigned integer. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** (uint) - The unsigned integer value associated with the key. #### Response Example ```json { "value": 100 } ``` ``` ```APIDOC ## GetUint8 ### Description GetUint8 returns the value associated with the key as an unsigned integer. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** (uint8) - The unsigned 8-bit integer value associated with the key. #### Response Example ```json { "value": 50 } ``` ``` ```APIDOC ## GetUint16 ### Description GetUint16 returns the value associated with the key as an unsigned integer. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** (uint16) - The unsigned 16-bit integer value associated with the key. #### Response Example ```json { "value": 200 } ``` ``` ```APIDOC ## GetUint32 ### Description GetUint32 returns the value associated with the key as an unsigned integer. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** (uint32) - The unsigned 32-bit integer value associated with the key. #### Response Example ```json { "value": 300 } ``` ``` ```APIDOC ## GetUint64 ### Description GetUint64 returns the value associated with the key as an unsigned integer. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **value** (uint64) - The unsigned 64-bit integer value associated with the key. #### Response Example ```json { "value": 400 } ``` ``` -------------------------------- ### Retrieve Configuration Values Source: https://pkg.go.dev/github.com/spf13/viper Demonstrates basic value retrieval using type-specific getter methods. ```go viper.GetString("logfile") // case-insensitive Setting & Getting if viper.GetBool("verbose") { fmt.Println("verbose enabled") } ``` -------------------------------- ### Initialize Viper Instances Source: https://pkg.go.dev/github.com/spf13/viper Functions to retrieve the global Viper instance or create new ones. ```go func GetViper() *Viper ``` ```go func New() *Viper ``` ```go func NewWithOptions(opts ...Option) *Viper ``` -------------------------------- ### Enable Debugging Output Source: https://pkg.go.dev/github.com/spf13/viper Prints all configuration registries for debugging purposes. ```go func Debug() ``` -------------------------------- ### Set Filesystem for Reading Config Source: https://pkg.go.dev/github.com/spf13/viper Sets the filesystem implementation to use for reading configuration files. This allows for custom or mocked filesystems. ```go func SetFs(fs afero.Fs) ``` -------------------------------- ### ConfigFileNotFoundError Error Method Source: https://pkg.go.dev/github.com/spf13/viper Returns the formatted configuration error. ```go func (fnfe ConfigFileNotFoundError) Error() string ``` -------------------------------- ### Set Environment Prefix Source: https://pkg.go.dev/github.com/spf13/viper Sets a prefix for environment variables. Viper will only consider environment variables that start with this prefix. ```APIDOC ## SetEnvPrefix ### Description Sets a prefix for environment variables. ### Method `SetEnvPrefix` ### Parameters - **in** (string) - Required - The prefix for environment variables. ``` -------------------------------- ### Set Configuration File Path Source: https://pkg.go.dev/github.com/spf13/viper Explicitly defines the path, name, and extension of the configuration file. Viper will use this path exclusively and will not search other configured paths. ```go func SetConfigFile(in string) ``` -------------------------------- ### Marshal All Settings to YAML String Source: https://pkg.go.dev/github.com/spf13/viper Convert all current Viper settings into a YAML formatted string using `AllSettings()` and an external YAML marshaller like `go.yaml.in/yaml/v3`. Handle potential marshalling errors. ```go import ( yaml "go.yaml.in/yaml/v3" // ... ) func yamlStringSettings() string { c := viper.AllSettings() bs, err := yaml.Marshal(c) if err != nil { log.Fatalf("unable to marshal config to YAML: %v", err) } return string(bs) } ``` -------------------------------- ### Handle Unsupported Configuration Errors Source: https://pkg.go.dev/github.com/spf13/viper Error types for unsupported file formats or remote providers. ```go type UnsupportedConfigError string ``` ```go func (str UnsupportedConfigError) Error() string ``` ```go type UnsupportedRemoteProviderError string ``` ```go func (str UnsupportedRemoteProviderError) Error() string ``` -------------------------------- ### Retrieve Any Value by Key Source: https://pkg.go.dev/github.com/spf13/viper Retrieves any value from the configuration given a key. This method is case-insensitive and checks sources in the order: override, flag, env, config file, key/value store, default. Returns an interface{}; use specific Get____ methods for typed values. ```go func Get(key string) any ``` -------------------------------- ### Bind Multiple PFlags to Viper Source: https://pkg.go.dev/github.com/spf13/viper Binds an existing set of pflags to Viper. This allows retrieving flag values through Viper's Get methods. ```go pflag.Int("flagname", 1234, "help message for flagname") pflag.Parse() vpr.BindPFlags(pflag.CommandLine) i := viper.GetInt("flagname") // retrieve values from viper instead of pflag ``` -------------------------------- ### Retrieve All Configuration Keys Source: https://pkg.go.dev/github.com/spf13/viper Returns all keys that hold a value, including nested keys separated by the configured delimiter. ```go func AllKeys() []string ``` -------------------------------- ### Bind Viper Key to pflag Source: https://pkg.go.dev/github.com/spf13/viper Binds a specific Viper key to a pflag, commonly used with the Cobra library. This example shows binding an integer flag named 'port'. ```go func BindPFlag(key string, flag *pflag.Flag) error ``` ```go serverCmd.Flags().Int("port", 1138, "Port to run Application server on") Viper.BindPFlag("port", serverCmd.Flags().Lookup("port")) ``` -------------------------------- ### Read Configuration File with Viper Source: https://pkg.go.dev/github.com/spf13/viper Configure Viper to search for and read a configuration file. Specify the config file name, type, and add multiple search paths. Handles errors during the reading process. ```go viper.SetConfigName("config") // name of config file (without extension) viper.SetConfigType("yaml") // REQUIRED if the config file does not have the extension in the name viper.AddConfigPath("/etc/appname/") // path to look for the config file in viper.AddConfigPath("$HOME/.appname") // call multiple times to add many search paths viper.AddConfigPath(".") // optionally look for config in the working directory err := viper.ReadInConfig() // Find and read the config file if err != nil { // Handle errors reading the config file panic(fmt.Errorf("fatal error config file: %w", err)) } ``` -------------------------------- ### Enable/Disable Type Inference by Default Value Source: https://pkg.go.dev/github.com/spf13/viper Enables or disables the inference of a key's value type based on its default value when using the Get function. If enabled, and a default is a slice, environment variables like 'a b c' will be parsed into a string slice. ```go func SetTypeByDefaultValue(enable bool) ``` ```go []string {"a", "b", "c"} ``` ```go "a b c" ``` -------------------------------- ### Run Viper Test Suite Source: https://pkg.go.dev/github.com/spf13/viper Executes the project's test suite using the Makefile. ```makefile make test ``` -------------------------------- ### Create and Use Multiple Viper Instances Source: https://pkg.go.dev/github.com/spf13/viper Instantiate multiple independent `viper.Viper` objects to manage distinct configuration sets. Each instance can have its own defaults, read from different sources, and be manipulated independently. ```go x := viper.New() y := viper.New() x.SetDefault("ContentDir", "content") y.SetDefault("ContentDir", "foobar") //... ``` -------------------------------- ### Write Current Configuration to File Source: https://pkg.go.dev/github.com/spf13/viper Write the current Viper configuration to a predefined path. Use 'WriteConfig' to overwrite an existing file or 'SafeWriteConfig' to only create it if it doesn't exist. ```go viper.WriteConfig() // writes current config to predefined path set by 'viper.AddConfigPath()' and 'viper.SetConfigName' viper.SafeWriteConfig() ``` -------------------------------- ### Finder Interface and Finders Function Source: https://pkg.go.dev/github.com/spf13/viper Looks for files and directories in an afero filesystem. ```go type Finder interface { Find(fsys afero.Fs) ([]string, error) } ``` ```go Output: bar ``` ```go func Finders(finders ...Finder) Finder ``` ```go Output: bar ``` -------------------------------- ### Configure etcd Remote Provider Source: https://pkg.go.dev/github.com/spf13/viper Initializes Viper to read configuration from an etcd key/value store. ```go viper.AddRemoteProvider("etcd", "http://127.0.0.1:4001","/config/hugo.json") viper.SetConfigType("json") // because there is no file extension in a stream of bytes, supported extensions are "json", "toml", "yaml", "yml", "properties", "props", "prop", "env", "dotenv" err := viper.ReadRemoteConfig() ``` -------------------------------- ### Set Configuration File Path Source: https://pkg.go.dev/github.com/spf13/viper Sets the path to the configuration file that Viper should use. ```APIDOC ## SetConfigFile ### Description Sets the path to the configuration file. ### Method `SetConfigFile` ### Parameters - **in** (string) - Required - The path to the configuration file. ``` -------------------------------- ### Configure Secure Remote Provider Source: https://pkg.go.dev/github.com/spf13/viper Initializes Viper to read encrypted configuration from a remote store using a GPG keyring. ```go viper.AddSecureRemoteProvider("etcd","http://127.0.0.1:4001","/config/hugo.json","/etc/secrets/mykeyring.gpg") viper.SetConfigType("json") // because there is no file extension in a stream of bytes, supported extensions are "json", "toml", "yaml", "yml", "properties", "props", "prop", "env", "dotenv" err := viper.ReadRemoteConfig() ``` -------------------------------- ### Register and Use Aliases for Keys Source: https://pkg.go.dev/github.com/spf13/viper Register aliases to reference a single configuration value using multiple keys. This allows for flexibility in configuration key naming. ```go viper.RegisterAlias("loud", "Verbose") viper.Set("verbose", true) // same result as next line viper.Set("loud", true) // same result as prior line viper.GetBool("loud") // true viper.GetBool("verbose") // true ``` -------------------------------- ### Configuration Setting Functions Source: https://pkg.go.dev/github.com/spf13/viper Functions for setting configuration values, defaults, and environment variable behaviors. ```APIDOC ## Set ### Description Sets the value for the key in the override register. Case-insensitive. ### Parameters - **key** (string) - Required - **value** (any) - Required ## SetDefault ### Description Sets the default value for a key. Used only when no other value is provided. ### Parameters - **key** (string) - Required - **value** (any) - Required ## SetEnvPrefix ### Description Defines a prefix that environment variables will use. ### Parameters - **in** (string) - Required ``` -------------------------------- ### Extracting a Configuration Sub-tree Source: https://pkg.go.dev/github.com/spf13/viper Use the `Sub` method to create a new Viper instance representing a specific section of the configuration. Always check the returned value for `nil` as it indicates the key was not found. ```go cache1Config := viper.Sub("cache.cache1") if cache1Config == nil { // Sub returns nil if the key cannot be found panic("cache configuration not found") } cache1 := NewCache(cache1Config) ``` ```go func NewCache(v *Viper) *Cache { return &Cache{ MaxItems: v.GetInt("max-items"), ItemSize: v.GetInt("item-size"), } } ``` -------------------------------- ### Configure etcd3 Remote Provider Source: https://pkg.go.dev/github.com/spf13/viper Initializes Viper to read configuration from an etcd3 key/value store. ```go viper.AddRemoteProvider("etcd3", "http://127.0.0.1:4001","/config/hugo.json") viper.SetConfigType("json") // because there is no file extension in a stream of bytes, supported extensions are "json", "toml", "yaml", "yml", "properties", "props", "prop", "env", "dotenv" err := viper.ReadRemoteConfig() ``` -------------------------------- ### Write Configuration As Source: https://pkg.go.dev/github.com/spf13/viper Writes the current configuration to a specified file. Added in v1.0.1. ```APIDOC ## WriteConfigAs ### Description Writes the current configuration to a specified file. Added in v1.0.1. ### Method `WriteConfigAs` ### Parameters - **filename** (string) - Required - The name of the file to write the configuration to. ### Returns - **error** - An error if writing fails. ``` -------------------------------- ### Write Current Configuration to File Source: https://pkg.go.dev/github.com/spf13/viper Writes the current configuration to a file. This function was added in v1.0.1. ```go func WriteConfig() error ``` -------------------------------- ### Read Configuration from io.Reader Source: https://pkg.go.dev/github.com/spf13/viper Read configuration directly from an io.Reader, such as a byte buffer. This is useful for providing configuration data programmatically or from non-file sources. ```go viper.SetConfigType("yaml") // or viper.SetConfigType("YAML") // any approach to require this configuration into your program. var yamlExample = []byte(` Hacker: true name: steve hobbies: - skateboarding - snowboarding - go clothing: jacket: leather trousers: denim age: 35 eyes : brown beard: true `) viper.ReadConfig(bytes.NewBuffer(yamlExample)) viper.Get("name") // this would be "steve" ``` -------------------------------- ### Viper Configuration Management Source: https://pkg.go.dev/github.com/spf13/viper Methods for reading, merging, and watching configuration files. ```APIDOC ## ReadConfig ### Description Reads configuration from an io.Reader. ### Parameters #### Request Body - **in** (io.Reader) - Required - The reader containing configuration data. ## OnConfigChange ### Description Sets the event handler that is called when a config file changes. ### Parameters #### Request Body - **run** (func(fsnotify.Event)) - Required - The callback function to execute on change. ``` -------------------------------- ### Finder Interface Source: https://pkg.go.dev/github.com/spf13/viper Interface for locating files and directories within an afero.Fs filesystem. ```APIDOC ## Finder Interface ### Description Looks for files and directories in an afero.Fs filesystem. ### Method Find(fsys afero.Fs) ([]string, error) ## Finders Function ### Description Combines multiple Finder instances into one. ### Method Finders(finders ...Finder) Finder ``` -------------------------------- ### Configure NATS Remote Provider Source: https://pkg.go.dev/github.com/spf13/viper Initializes Viper to read configuration from a NATS key/value store. ```go viper.AddRemoteProvider("nats", "nats://127.0.0.1:4222", "myapp.config") viper.SetConfigType("json") err := viper.ReadRemoteConfig() ``` -------------------------------- ### Configuration Status and Checks Source: https://pkg.go.dev/github.com/spf13/viper Functions to check if a key exists in the configuration or environment. ```APIDOC ## InConfig ### Description InConfig checks to see if the given key (or an alias) is in the config file. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **exists** (bool) - True if the key is found in the config file, false otherwise. #### Response Example ```json { "exists": true } ``` ``` ```APIDOC ## IsSet ### Description IsSet checks to see if the key has been set in any of the data locations. IsSet is case-insensitive for a key. ### Method GET ### Endpoint N/A (Function within a library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **isSet** (bool) - True if the key is set, false otherwise. #### Response Example ```json { "isSet": true } ``` ```