summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/run.go2
-rw-r--r--internal/state.go13
2 files changed, 13 insertions, 2 deletions
diff --git a/internal/run.go b/internal/run.go
index 701d200..b48c19c 100644
--- a/internal/run.go
+++ b/internal/run.go
@@ -17,7 +17,7 @@ func Run(ctx context.Context, configFile string, renotify, force bool) {
notifyError(conf, err)
}
- state, err := readState(conf)
+ state, err := newState(conf)
if err != nil {
notifyError(conf, err)
}
diff --git a/internal/state.go b/internal/state.go
index f37a0f6..d37ecf4 100644
--- a/internal/state.go
+++ b/internal/state.go
@@ -26,7 +26,7 @@ type state struct {
checks map[string]checkState
}
-func readState(conf config) (state, error) {
+func newState(conf config) (state, error) {
s := state{
stateFile: fmt.Sprintf("%s/state.json", conf.StateDir),
checks: make(map[string]checkState),
@@ -79,6 +79,17 @@ func (s state) update(result checkResult) {
log.Println(result.name, cs)
}
+// To be used to merge the state of another server running Gogios
+func (s state) merge(other state) error {
+ for name, cs := range other.checks {
+ if _, ok := s.checks[name]; ok {
+ return fmt.Errorf("can't merge state due to duplicate check name '%s'", name)
+ }
+ s.checks[name] = cs
+ }
+ return nil
+}
+
func (s state) persist() error {
stateDir := filepath.Dir(s.stateFile)
if _, err := os.Stat(stateDir); os.IsNotExist(err) {