Documentation ¶
Overview ¶
Example ¶
package main import ( "path" "github.com/sraphs/go/config" "github.com/sraphs/go/config/env" "github.com/sraphs/go/config/file" "github.com/sraphs/go/config/flag" testData "github.com/sraphs/go/config/internal/testdata" ) func main() { p := path.Join("internal", "testdata") c := config.New( config.WithSource( env.NewSource("sraph_"), file.NewSource(p), flag.NewSource(), ), ) if err := c.Load(); err != nil { panic(err) } var conf testData.Conf if err := c.Scan(&conf); err != nil { panic(err) } c.Watch(func(c config.Config) { c.Scan(&conf) }) // fmt.Println(conf) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrUnsupportedFormat = errors.New("unsupported format")
)
View Source
var (
SupportedFormats = []string{"env", "json", "xml", "yaml", "yml"}
)
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config interface { Load() error Scan(v interface{}) error Watch(o Observer) error Close() error }
Config is a config interface.
type Descriptor ¶
Descriptor is file or env or flag descriptor.
func (*Descriptor) GetCodec ¶
func (d *Descriptor) GetCodec() encoding.Codec
type Source ¶
type Source interface { Load() ([]*Descriptor, error) Watch() (Watcher, error) }
Source is config source.
type Watcher ¶
type Watcher interface { Next() ([]*Descriptor, error) Stop() error }
Watcher watches a source for changes.
Click to show internal directories.
Click to hide internal directories.