2019-05-31 00:11:13 +02:00
|
|
|
// package loader manages loading from multiple sources
|
|
|
|
package loader
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-01-20 15:54:31 +02:00
|
|
|
"github.com/asim/go-micro/v3/config/reader"
|
|
|
|
"github.com/asim/go-micro/v3/config/source"
|
2019-05-31 00:11:13 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Loader manages loading sources
|
|
|
|
type Loader interface {
|
|
|
|
// Stop the loader
|
|
|
|
Close() error
|
|
|
|
// Load the sources
|
|
|
|
Load(...source.Source) error
|
|
|
|
// A Snapshot of loaded config
|
|
|
|
Snapshot() (*Snapshot, error)
|
|
|
|
// Force sync of sources
|
|
|
|
Sync() error
|
|
|
|
// Watch for changes
|
|
|
|
Watch(...string) (Watcher, error)
|
|
|
|
// Name of loader
|
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Watcher lets you watch sources and returns a merged ChangeSet
|
|
|
|
type Watcher interface {
|
|
|
|
// First call to next may return the current Snapshot
|
|
|
|
// If you are watching a path then only the data from
|
|
|
|
// that path is returned.
|
|
|
|
Next() (*Snapshot, error)
|
|
|
|
// Stop watching for changes
|
|
|
|
Stop() error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Snapshot is a merged ChangeSet
|
|
|
|
type Snapshot struct {
|
|
|
|
// The merged ChangeSet
|
|
|
|
ChangeSet *source.ChangeSet
|
|
|
|
// Deterministic and comparable version of the snapshot
|
|
|
|
Version string
|
|
|
|
}
|
|
|
|
|
|
|
|
type Options struct {
|
|
|
|
Reader reader.Reader
|
|
|
|
Source []source.Source
|
|
|
|
|
|
|
|
// for alternative data
|
|
|
|
Context context.Context
|
2022-04-19 07:26:14 +02:00
|
|
|
|
|
|
|
WithWatcherDisabled bool
|
2019-05-31 00:11:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type Option func(o *Options)
|
|
|
|
|
|
|
|
// Copy snapshot
|
|
|
|
func Copy(s *Snapshot) *Snapshot {
|
|
|
|
cs := *(s.ChangeSet)
|
|
|
|
|
|
|
|
return &Snapshot{
|
|
|
|
ChangeSet: &cs,
|
|
|
|
Version: s.Version,
|
|
|
|
}
|
|
|
|
}
|