diff options
| author | Paul Buetow <paul@buetow.org> | 2023-05-21 23:49:03 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-05-21 23:49:03 +0300 |
| commit | e958dc957a2339228bfe74865b4e1728484f4fd0 (patch) | |
| tree | 186bdf561be5a122e122f94106fd2d82aece1fe3 /internal/quorum.go | |
| parent | 6cd559398b5b1183c19ac0ab2b5840b02132489c (diff) | |
refactor config to separate package
Diffstat (limited to 'internal/quorum.go')
| -rw-r--r-- | internal/quorum.go | 12 |
1 files changed, 7 insertions, 5 deletions
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_ }) |
