1
0

loader.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // package loader manages loading from multiple sources
  2. package loader
  3. import (
  4. "context"
  5. "gogs.baozhida.cn/zoie/OAuth-core/config/reader"
  6. "gogs.baozhida.cn/zoie/OAuth-core/config/source"
  7. )
  8. // Loader manages loading sources
  9. type Loader interface {
  10. // Close Stop the loader
  11. Close() error
  12. // Load the sources
  13. Load(...source.Source) error
  14. // Snapshot A Snapshot of loaded config
  15. Snapshot() (*Snapshot, error)
  16. // Sync Force sync of sources
  17. Sync() error
  18. // Watch for changes
  19. Watch(...string) (Watcher, error)
  20. // String Name of loader
  21. String() string
  22. }
  23. // Watcher lets you watch sources and returns a merged ChangeSet
  24. type Watcher interface {
  25. // Next First call to next may return the current Snapshot
  26. // If you are watching a path then only the data from
  27. // that path is returned.
  28. Next() (*Snapshot, error)
  29. // Stop watching for changes
  30. Stop() error
  31. }
  32. // Snapshot is a merged ChangeSet
  33. type Snapshot struct {
  34. // The merged ChangeSet
  35. ChangeSet *source.ChangeSet
  36. // Version Deterministic and comparable version of the snapshot
  37. Version string
  38. }
  39. type Options struct {
  40. Reader reader.Reader
  41. Source []source.Source
  42. // for alternative data
  43. Context context.Context
  44. }
  45. type Option func(o *Options)
  46. // Copy snapshot
  47. func Copy(s *Snapshot) *Snapshot {
  48. cs := *(s.ChangeSet)
  49. return &Snapshot{
  50. ChangeSet: &cs,
  51. Version: s.Version,
  52. }
  53. }