conf.go
conf.go - Overview
-
Overview This file defines a
Conf
struct, which is a wrapper around thekoanf
library, used for managing configuration data. It provides methods for creating, merging, unmarshaling, and setting configuration values. It also includes custom decode hook functions formapstructure
. -
Detailed Documentation
const KoanfDelimiter
- Purpose: Defines the delimiter used by
koanf
for nested configuration keys. - Value:
"::"
type Conf
- Purpose: Represents a configuration object, wrapping a
koanf.Koanf
instance. - Fields:
Koanf
: A pointer to akoanf.Koanf
instance, providing the underlying configuration management functionality.
func NewConf() *Conf
- Purpose: Creates a new
Conf
instance with a newkoanf.Koanf
instance, using the definedKoanfDelimiter
. - Parameters: None
- Returns: A pointer to the newly created
Conf
instance.
func NewConfFromMap(m map[string]any) (*Conf, error)
- Purpose: Creates a new
Conf
instance and loads configuration data from a map. - Parameters:
m
(map[string]any): The map containing the configuration data.
- Returns:
- A pointer to the new
Conf
instance if successful,nil
otherwise. - An error if loading the configuration from the map fails.
- A pointer to the new
func MustNewConfFromMap(m map[string]any) *Conf
- Purpose: Creates a new
Conf
instance from a map and panics if an error occurs during creation. - Parameters:
m
(map[string]any): The map containing configuration data.
- Returns: A pointer to the new
Conf
instance. - Panics: If
NewConfFromMap
returns an error.
func (conf *Conf) Merge(input *Conf) error
- Purpose: Merges the configuration from another
Conf
instance into the currentConf
instance. - Parameters:
input
(*Conf): TheConf
instance to merge into the current instance.
- Returns: An error if the merge operation fails.
func (conf *Conf) MergeAt(input *Conf, path string) error
- Purpose: Merges the configuration from another
Conf
instance into the currentConf
instance at a specified path. - Parameters:
input
(*Conf): TheConf
instance to merge.path
(string): The path at which to merge the configuration.
- Returns: An error if the merge operation fails.
func (conf *Conf) Unmarshal(path string, input any, tags ...string) error
- Purpose: Unmarshals the configuration data at the given path into the provided input variable. It supports custom decode hooks and uses "mapstructure" tags by default.
- Parameters:
path
(string): The configuration path to unmarshal from.input
(any): The variable to unmarshal the configuration data into.tags
(...string): Optional tags to use for unmarshaling (defaults to "mapstructure").
- Returns: An error if unmarshaling fails.
func (conf *Conf) Set(key string, input any) error
- Purpose: Sets the configuration value at the given key by decoding the input and merging it into the configuration.
- Parameters:
key
(string): The configuration key to set.input
(any): The value to set at the given key.
- Returns: An error if decoding or merging fails.
func StringToURLHookFunc() mapstructure.DecodeHookFunc
- Purpose: Provides a
mapstructure
decode hook for converting strings tourl.URL
instances. - Parameters: None
- Returns: A
mapstructure.DecodeHookFunc
that attempts to parse strings as URLs.
func YamlV2UnmarshalHookFunc() mapstructure.DecodeHookFunc
- Purpose: Provides a
mapstructure
decode hook for unmarshaling strings as YAML usinggopkg.in/yaml.v2
. - Parameters: None
- Returns: A
mapstructure.DecodeHookFunc
that attempts to unmarshal strings as YAML.
-
Code Examples N/A
-
Clarity and Accuracy The documentation accurately reflects the code.
-
Markdown & MDX Perfection The markdown is valid.
-
Edge Cases To Avoid Breaking MDX No issues.
-
Getting Started Relevance Include in Getting Started: YES