From e958dc957a2339228bfe74865b4e1728484f4fd0 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 21 May 2023 23:49:03 +0300 Subject: refactor config to separate package --- internal/quorum.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'internal/quorum.go') diff --git a/internal/quorum.go b/internal/quorum.go index 179efb1..b680378 100644 --- a/internal/quorum.go +++ b/internal/quorum.go @@ -4,6 +4,8 @@ import ( "fmt" "log" "sort" + + "codeberg.org/snonux/gorum/internal/config" ) type quorumMap map[string]vote @@ -18,15 +20,15 @@ func (q quorumMap) vote(v vote) { q[v.from] = v } -func (q quorumMap) winner(config config) (string, error) { - scores := q.score(config) +func (q quorumMap) winner(conf config.Config) (string, error) { + scores := q.score(conf) if len(scores) == 0 { return "", fmt.Errorf("unable to find a winner, empty score list") } return scores[0].id, nil } -func (q quorumMap) score(config config) (scores []score) { +func (q quorumMap) score(conf config.Config) (scores []score) { scoreMap := make(map[string]int) for _, vote := range q { @@ -46,8 +48,8 @@ func (q quorumMap) score(config config) (scores []score) { } // Score tie, use participant number. - i_, _ := config.participantNumber(scores[i].id) - j_, _ := config.participantNumber(scores[j].id) + i_, _ := conf.ParticipantNumber(scores[i].id) + j_, _ := conf.ParticipantNumber(scores[j].id) return i_ < j_ }) -- cgit v1.2.3