Documentation
¶
Overview ¶
Package goconf is a simple, straightforward go configuration library.
Configuration is defined via structs and tags. Values are loaded from files.
Any file format can be used.
Example (Toml) ¶
Simple configuration setup using Toml files
package main
import (
"github.com/Noah-Huppert/goconf"
"github.com/Noah-Huppert/goconf/toml"
)
func main() {
// import "github.com/Noah-Huppert/goconf"
// import "github.com/Noah-Huppert/goconf/toml"
// Create goconf instance
loader := goconf.NewLoader()
// Register file formats
loader.RegisterFormat(".toml", toml.TomlMapDecoder{})
// Define locations to search for configuration files
// Can use shell globs
loader.AddConfigPath("/etc/foo/foo.*")
loader.AddConfigPath("/etc/foo.d/*")
// Load values
type YourConfigStruct struct {
Foo string `mapstructure:"foo"`
Bar string `mapstructure:"bar"`
}
config := YourConfigStruct{}
err := loader.Load(&config)
panic(err)
}
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader loads configuration
func (*Loader) AddConfigPath ¶
AddConfigPath adds a potential path from which configuration files will be loaded. Must point to file(s) not of directories. The p argument can contain shell globs.
func (*Loader) RegisterFormat ¶
func (l *Loader) RegisterFormat(ext string, decoder MapDecoder)
RegisterFormat registers a MapDecoder to be used for a file extension. The ext argument should include the final dot and then the extension name. An empty string can be passed to target files without an extension.
Click to show internal directories.
Click to hide internal directories.