summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/wiggin77/cfg/source.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-10-19 23:40:00 +0200
committerGitHub <noreply@github.com>2020-10-19 23:40:00 +0200
commit075a84427f6332aab707d283ad770d69f8816032 (patch)
tree0ff9f56a057919f3fe968e57f6f0b1c0d1f85078 /vendor/github.com/wiggin77/cfg/source.go
parent950f2759bd2b20aa0bdedc3dc9a74d0dafb606d8 (diff)
downloadmatterbridge-msglm-075a84427f6332aab707d283ad770d69f8816032.tar.gz
matterbridge-msglm-075a84427f6332aab707d283ad770d69f8816032.tar.bz2
matterbridge-msglm-075a84427f6332aab707d283ad770d69f8816032.zip
Update vendor (#1265)
Diffstat (limited to 'vendor/github.com/wiggin77/cfg/source.go')
-rw-r--r--vendor/github.com/wiggin77/cfg/source.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/vendor/github.com/wiggin77/cfg/source.go b/vendor/github.com/wiggin77/cfg/source.go
new file mode 100644
index 00000000..09083e97
--- /dev/null
+++ b/vendor/github.com/wiggin77/cfg/source.go
@@ -0,0 +1,58 @@
+package cfg
+
+import (
+ "sync"
+ "time"
+)
+
+// Source is the interface required for any source of name/value pairs.
+type Source interface {
+
+ // GetProps fetches all the properties from a source and returns
+ // them as a map.
+ GetProps() (map[string]string, error)
+}
+
+// SourceMonitored is the interface required for any config source that is
+// monitored for changes.
+type SourceMonitored interface {
+ Source
+
+ // GetLastModified returns the time of the latest modification to any
+ // property value within the source. If a source does not support
+ // modifying properties at runtime then the zero value for `Time`
+ // should be returned to ensure reload events are not generated.
+ GetLastModified() (time.Time, error)
+
+ // GetMonitorFreq returns the frequency as a `time.Duration` between
+ // checks for changes to this config source.
+ //
+ // Returning zero (or less) will temporarily suspend calls to `GetLastModified`
+ // and `GetMonitorFreq` will be called every 10 seconds until resumed, after which
+ // `GetMontitorFreq` will be called at a frequency roughly equal to the `time.Duration`
+ // returned.
+ GetMonitorFreq() time.Duration
+}
+
+// AbstractSourceMonitor can be embedded in a custom `Source` to provide the
+// basic plumbing for monitor frequency.
+type AbstractSourceMonitor struct {
+ mutex sync.RWMutex
+ freq time.Duration
+}
+
+// GetMonitorFreq returns the frequency as a `time.Duration` between
+// checks for changes to this config source.
+func (asm *AbstractSourceMonitor) GetMonitorFreq() (freq time.Duration) {
+ asm.mutex.RLock()
+ freq = asm.freq
+ asm.mutex.RUnlock()
+ return
+}
+
+// SetMonitorFreq sets the frequency between checks for changes to this config source.
+func (asm *AbstractSourceMonitor) SetMonitorFreq(freq time.Duration) {
+ asm.mutex.Lock()
+ asm.freq = freq
+ asm.mutex.Unlock()
+}