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