diff options
| author | Paul Buetow <paul@buetow.org> | 2023-10-21 12:47:46 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-10-21 12:47:46 +0300 |
| commit | 61919768cfe4df8fbd709e8e6034f4c4c83def27 (patch) | |
| tree | 17e69ec1a57aee73eb7300bf0bc9353ec29a9969 /internal | |
| parent | 8af37a343946ee904b421cb6353ea294e31804df (diff) | |
make score file and winner file names configurable.
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/config/config.go | 10 | ||||
| -rw-r--r-- | internal/quorum/quorum.go | 4 | ||||
| -rw-r--r-- | internal/server/server.go | 1 |
3 files changed, 10 insertions, 5 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 988315a..a882268 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -13,6 +13,8 @@ import ( type Config struct { StateDir string + ScoreFile string + WinnerFile string Address string Nodes []string LoopIntervalS int64 `json:"LoopIntervalS,omitempty"` @@ -87,10 +89,15 @@ func WithRelaxedMode() func(*Config) { } func (conf Config) setDefaults() (Config, error) { + if conf.ScoreFile == "" { + conf.ScoreFile = "scores" + } + if conf.WinnerFile == "" { + conf.WinnerFile = "is_winner" + } if conf.LoopIntervalS == 0 { conf.LoopIntervalS = 10 } - if conf.MyID == "" { hostname, err := os.Hostname() if err != nil { @@ -103,7 +110,6 @@ func (conf Config) setDefaults() (Config, error) { for i, node := range conf.Nodes { conf.nodeNumberCache[utils.StripPort(node)] = i } - return conf, nil } diff --git a/internal/quorum/quorum.go b/internal/quorum/quorum.go index b29b428..9bce682 100644 --- a/internal/quorum/quorum.go +++ b/internal/quorum/quorum.go @@ -185,11 +185,11 @@ func (quo *Quorum) persist(changed bool) error { return err } - return writeFileViaTmp(fmt.Sprintf("%s/scores", quo.conf.StateDir), scoresStr) + return writeFileViaTmp(fmt.Sprintf("%s/%s", quo.conf.StateDir, quo.conf.ScoreFile), scoresStr) } func (quo *Quorum) persistWinner(winnerStr string) error { - winnerFile := fmt.Sprintf("%s/is_winner", quo.conf.StateDir) + winnerFile := fmt.Sprintf("%s/%s", quo.conf.StateDir, quo.conf.WinnerFile) if winnerStr == "" { if _, err := os.Stat(winnerFile); err != nil { return os.Remove(winnerFile) diff --git a/internal/server/server.go b/internal/server/server.go index c3e9e05..806d3a1 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -32,7 +32,6 @@ func runServer(ctx context.Context, conf config.Config, quo quorum.Quorum) error defer cancel() ch := make(chan vote.Vote) - go func() { for { select { |
