github.com/Cloud-Foundations/Dominator@v0.3.4/lib/configwatch/api.go (about)

     1  /*
     2  	Package configwatch watches local or remote config files for changes.
     3  */
     4  package configwatch
     5  
     6  import (
     7  	"io"
     8  	"time"
     9  
    10  	"github.com/Cloud-Foundations/Dominator/lib/log"
    11  )
    12  
    13  type Decoder func(reader io.Reader) (interface{}, error)
    14  
    15  // Watch is designed to monitor configuration changes. Watch will monitor the
    16  // provided URL for new data, calling the decoder and will send the decoded data
    17  // to the channel that is returned. Decoded data are not sent if the checksum of
    18  // the raw data has not changed since the last decoded data were sent to the
    19  // channel. The URL is checked for changed data at least every checkInterval
    20  // (for HTTP/HTTPS URLs) but may be checked more frequently (for local files).
    21  func Watch(url string, checkInterval time.Duration,
    22  	decoder Decoder, logger log.DebugLogger) (<-chan interface{}, error) {
    23  	return watch(url, checkInterval, decoder, logger)
    24  }
    25  
    26  // WatchWithCache is similar to Watch, except that successfully decoded data are
    27  // cached.
    28  // A cached copy of the data is stored in the file named cacheFilename. This
    29  // file is read at startup if the URL is not available before the
    30  // initialTimeout.
    31  func WatchWithCache(url string, checkInterval time.Duration,
    32  	decoder Decoder, cacheFilename string, initialTimeout time.Duration,
    33  	logger log.DebugLogger) (<-chan interface{}, error) {
    34  	return watchWithCache(url, checkInterval, decoder, cacheFilename,
    35  		initialTimeout, logger)
    36  }