From 1eb99dc0b6d04d85b9736ab5a050e08d410abb4a Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 21 May 2023 23:57:53 +0300 Subject: refactor vote into its own package --- internal/quorum.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'internal/quorum.go') 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) } } -- cgit v1.2.3