1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-01-05 10:20:53 +02:00
go-micro/config/loader/loader.go

69 lines
1.4 KiB
Go
Raw Permalink Normal View History

2022-09-30 20:32:55 +02:00
// Package loader manages loading from multiple sources
2019-05-31 00:11:13 +02:00
package loader
import (
"context"
2024-06-04 22:40:43 +02:00
"go-micro.dev/v5/config/reader"
"go-micro.dev/v5/config/source"
2019-05-31 00:11:13 +02:00
)
2022-09-30 16:27:07 +02:00
// Loader manages loading sources.
2019-05-31 00:11:13 +02:00
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
}
2022-09-30 16:27:07 +02:00
// Watcher lets you watch sources and returns a merged ChangeSet.
2019-05-31 00:11:13 +02:00
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
}
2022-09-30 16:27:07 +02:00
// Snapshot is a merged ChangeSet.
2019-05-31 00:11:13 +02:00
type Snapshot struct {
// The merged ChangeSet
ChangeSet *source.ChangeSet
// Deterministic and comparable version of the snapshot
Version string
}
2022-09-30 20:32:55 +02:00
// Options contains all options for a config loader.
2019-05-31 00:11:13 +02:00
type Options struct {
Reader reader.Reader
// for alternative data
Context context.Context
2023-04-26 02:16:34 +02:00
Source []source.Source
WithWatcherDisabled bool
2019-05-31 00:11:13 +02:00
}
2022-09-30 20:32:55 +02:00
// Option is a helper for a single option.
2019-05-31 00:11:13 +02:00
type Option func(o *Options)
2022-09-30 16:27:07 +02:00
// Copy snapshot.
2019-05-31 00:11:13 +02:00
func Copy(s *Snapshot) *Snapshot {
cs := *(s.ChangeSet)
return &Snapshot{
ChangeSet: &cs,
Version: s.Version,
}
}