📝 README and inline docs
This commit is contained in:
parent
d533a879ef
commit
c61300c6b8
14 changed files with 139 additions and 24 deletions
|
|
@ -5,8 +5,10 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// Quorum defines a custom uint8 type for storing a quorum.
|
||||
type Quorum uint8
|
||||
|
||||
// Supported quorums are:
|
||||
const (
|
||||
Simple Quorum = iota
|
||||
OneFifth
|
||||
|
|
@ -21,6 +23,7 @@ const (
|
|||
Unanimous
|
||||
)
|
||||
|
||||
// ValidQuorums returns a []Quorum of all supported quorums.
|
||||
func ValidQuorums() []Quorum {
|
||||
return []Quorum{
|
||||
Simple, Unanimous,
|
||||
|
|
@ -31,6 +34,8 @@ func ValidQuorums() []Quorum {
|
|||
}
|
||||
}
|
||||
|
||||
// FromString takes a string and returns an initialized Quorum or an error if
|
||||
// the string could not be parsed.
|
||||
func FromString(s string) (Quorum, error) {
|
||||
for _, q := range ValidQuorums() {
|
||||
if strings.ToUpper(q.String()) == strings.ToUpper(s) {
|
||||
|
|
@ -40,6 +45,7 @@ func FromString(s string) (Quorum, error) {
|
|||
return Simple, fmt.Errorf("inalid quorum: %s", s)
|
||||
}
|
||||
|
||||
// String implements fmt.Stringer
|
||||
func (q Quorum) String() string {
|
||||
switch q {
|
||||
case Simple:
|
||||
|
|
@ -69,6 +75,8 @@ func (q Quorum) String() string {
|
|||
}
|
||||
}
|
||||
|
||||
// IsSatisfied takes the number of eligible and actual votes and returns a bool
|
||||
// indicating if the quroum is satisfied or not.
|
||||
func (q Quorum) IsSatisfied(possibleVotes, totalVotes int) bool {
|
||||
if totalVotes == 0 {
|
||||
return false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue