Documentation
¶
Overview ¶
Package config provides means to access configuration data at runtime in a type-safe manner
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Interface ¶
type Interface interface {
// Get fills the structPtr with configuration values found at key
Get(key string, structPtr interface{}) error
// Keys returns the top level keys of the configuration data
Keys() []string
}
Interface is an abstraction around the underlying configuration
func Init ¶
Init initializes a config.Interface using the provided config.Option's An error is returned when there is an issue reading in the configuration
Example ¶
package main
import (
"fmt"
"github.com/wgentry22/config"
"strings"
)
func main() {
type configData struct {
Value string `mapstructure:"value"`
}
yamlReader := strings.NewReader(`
data:
value: Hello, World!
`)
readerOption := config.Reader(yamlReader)
// yaml is the default value
configExtensionOption := config.Extension("yaml")
options := []config.Option{readerOption, configExtensionOption}
// Could also use the following
// configFileOption := config.Name("myConfigFileName")
// configPathsOption := config.Paths("/my/absolute/path/to/config", "./my/relative/path/to/config")
// options := []config.Option{configFileOption, configPathsOption, configExtensionOption}
conf, err := config.Init(options...)
if err != nil {
panic(err)
}
var confData configData
if err := conf.Get(`data`, &confData); err != nil {
panic(err)
}
fmt.Println(confData.Value)
}
Output:
type Option ¶
type Option func(*Options)
Option functions allow for customization of the associated Options
func Extension ¶
Extension is an Option that sets the file extension of the configuration file to search for
func Hooks ¶
func Hooks(hooks ...mapstructure.DecodeHookFunc) Option
Hooks is an Option which allows additional customization of how to unmarshal the underlying configuration into a struct
Click to show internal directories.
Click to hide internal directories.