diff options
| author | Paul Buetow <paul@buetow.org> | 2025-05-28 22:58:48 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-05-28 22:58:48 +0300 |
| commit | 34b54e7285eb084c8fb9abc7b3b8cb90a4438f9a (patch) | |
| tree | b7fb93b9d17a85c8c63bc60d0d032b661f78c478 | |
| parent | 8b43dff3070d869fbb28c50d8c24d608c608d629 (diff) | |
initial merge state
| -rw-r--r-- | internal/run.go | 2 | ||||
| -rw-r--r-- | internal/state.go | 13 |
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) { |
