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"
)
func main() {
// import "github.com/Noah-Huppert/goconf"
// Create goconf instance
loader := goconf.NewLoader()
// 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" validate:"required"`
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 NewDefaultLoader ¶ added in v0.1.1
func NewDefaultLoader() *Loader
NewDefaultLoader creates a Loader with all MapDecoders implemented by goconf.
func NewLoader ¶
func NewLoader() *Loader
NewLoader creates a Loader with all MapDecoders implemented by goconf.
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) GetValidate ¶ added in v0.2.1
GetValidate returns the validator instance used to validate configuration
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.