2019-05-31 00:11:13 +02:00
|
|
|
// Package source is the interface for sources
|
|
|
|
package source
|
|
|
|
|
|
|
|
import (
|
2019-08-20 23:32:47 +02:00
|
|
|
"errors"
|
2019-05-31 00:11:13 +02:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2019-08-20 23:32:47 +02:00
|
|
|
var (
|
2022-09-30 16:27:07 +02:00
|
|
|
// ErrWatcherStopped is returned when source watcher has been stopped.
|
2019-08-20 23:32:47 +02:00
|
|
|
ErrWatcherStopped = errors.New("watcher stopped")
|
|
|
|
)
|
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// Source is the source from which config is loaded.
|
2019-05-31 00:11:13 +02:00
|
|
|
type Source interface {
|
|
|
|
Read() (*ChangeSet, error)
|
2019-12-23 10:42:57 +02:00
|
|
|
Write(*ChangeSet) error
|
2019-12-23 10:49:53 +02:00
|
|
|
Watch() (Watcher, error)
|
2019-05-31 00:11:13 +02:00
|
|
|
String() string
|
|
|
|
}
|
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// ChangeSet represents a set of changes from a source.
|
2019-05-31 00:11:13 +02:00
|
|
|
type ChangeSet struct {
|
2023-04-26 02:16:34 +02:00
|
|
|
Timestamp time.Time
|
2019-05-31 00:11:13 +02:00
|
|
|
Checksum string
|
|
|
|
Format string
|
|
|
|
Source string
|
2023-04-26 02:16:34 +02:00
|
|
|
Data []byte
|
2019-05-31 00:11:13 +02:00
|
|
|
}
|
|
|
|
|
2022-09-30 16:27:07 +02:00
|
|
|
// Watcher watches a source for changes.
|
2019-05-31 00:11:13 +02:00
|
|
|
type Watcher interface {
|
|
|
|
Next() (*ChangeSet, error)
|
|
|
|
Stop() error
|
|
|
|
}
|