go-micro.dev/v5@v5.12.0/config/loader/loader.go (about)

     1  // Package loader manages loading from multiple sources
     2  package loader
     3  
     4  import (
     5  	"context"
     6  
     7  	"go-micro.dev/v5/config/reader"
     8  	"go-micro.dev/v5/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  // Options contains all options for a config loader.
    46  type Options struct {
    47  	Reader reader.Reader
    48  
    49  	// for alternative data
    50  	Context context.Context
    51  
    52  	Source []source.Source
    53  
    54  	WithWatcherDisabled bool
    55  }
    56  
    57  // Option is a helper for a single option.
    58  type Option func(o *Options)
    59  
    60  // Copy snapshot.
    61  func Copy(s *Snapshot) *Snapshot {
    62  	cs := *(s.ChangeSet)
    63  
    64  	return &Snapshot{
    65  		ChangeSet: &cs,
    66  		Version:   s.Version,
    67  	}
    68  }