diff options
| author | Paul Buetow <paul@buetow.org> | 2023-05-21 23:57:53 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-05-21 23:57:53 +0300 |
| commit | 1eb99dc0b6d04d85b9736ab5a050e08d410abb4a (patch) | |
| tree | 77ec95510f0ce6de5f20aea2f5e7c12c91dd23bd /internal/quorum.go | |
| parent | e958dc957a2339228bfe74865b4e1728484f4fd0 (diff) | |
refactor vote into its own package
Diffstat (limited to 'internal/quorum.go')
| -rw-r--r-- | internal/quorum.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/internal/quorum.go b/internal/quorum.go index b680378..a64b07b 100644 --- a/internal/quorum.go +++ b/internal/quorum.go @@ -6,18 +6,19 @@ import ( "sort" "codeberg.org/snonux/gorum/internal/config" + "codeberg.org/snonux/gorum/internal/vote" ) -type quorumMap map[string]vote +type quorumMap map[string]vote.Vote type score struct { id string score int } -func (q quorumMap) vote(v vote) { +func (q quorumMap) vote(v vote.Vote) { log.Printf("Adding vote %v", v) - q[v.from] = v + q[v.From] = v } func (q quorumMap) winner(conf config.Config) (string, error) { @@ -32,7 +33,7 @@ func (q quorumMap) score(conf config.Config) (scores []score) { scoreMap := make(map[string]int) for _, vote := range q { - for _, id := range vote.ids { + for _, id := range vote.IDs { score, _ := scoreMap[id] scoreMap[id] = score + 1 } @@ -60,7 +61,7 @@ func (q quorumMap) cleanExpired() { var expired []string for from, vote := range q { - if vote.expired() { + if vote.Expired() { expired = append(expired, from) } } |
