🚨 go fmt; go mod tidy
This commit is contained in:
parent
fb2a29be51
commit
b0657a3fb2
20 changed files with 715 additions and 722 deletions
|
|
@ -8,33 +8,33 @@ import (
|
|||
type Choice int8
|
||||
|
||||
func (choice Choice) String() string {
|
||||
switch choice {
|
||||
case Yes:
|
||||
return "YIP"
|
||||
case No:
|
||||
return "NOPE"
|
||||
case Abstain:
|
||||
return "DUNNO"
|
||||
default:
|
||||
panic("this code should never be reached")
|
||||
}
|
||||
switch choice {
|
||||
case Yes:
|
||||
return "YIP"
|
||||
case No:
|
||||
return "NOPE"
|
||||
case Abstain:
|
||||
return "DUNNO"
|
||||
default:
|
||||
panic("this code should never be reached")
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
Abstain Choice = 0
|
||||
Yes Choice = 1
|
||||
No Choice = -1
|
||||
Abstain Choice = 0
|
||||
Yes Choice = 1
|
||||
No Choice = -1
|
||||
)
|
||||
|
||||
func ValidChoices() []Choice {
|
||||
return []Choice{Yes, No, Abstain}
|
||||
return []Choice{Yes, No, Abstain}
|
||||
}
|
||||
|
||||
func ChoiceFromString(s string) (Choice, error) {
|
||||
for _, c := range ValidChoices() {
|
||||
if strings.ToUpper(c.String()) == strings.ToUpper(s) {
|
||||
return c, nil
|
||||
}
|
||||
}
|
||||
return Abstain, fmt.Errorf("invalid choice: %s", s)
|
||||
for _, c := range ValidChoices() {
|
||||
if strings.ToUpper(c.String()) == strings.ToUpper(s) {
|
||||
return c, nil
|
||||
}
|
||||
}
|
||||
return Abstain, fmt.Errorf("invalid choice: %s", s)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,27 +6,27 @@ import (
|
|||
)
|
||||
|
||||
type Vote struct {
|
||||
Elector string
|
||||
Choice Choice
|
||||
timestamp time.Time
|
||||
Elector string
|
||||
Choice Choice
|
||||
timestamp time.Time
|
||||
}
|
||||
|
||||
func NewVote(elector string, choice Choice) Vote {
|
||||
return Vote{
|
||||
Elector: elector,
|
||||
Choice: choice,
|
||||
timestamp: time.Now().UTC(),
|
||||
}
|
||||
return Vote{
|
||||
Elector: elector,
|
||||
Choice: choice,
|
||||
timestamp: time.Now().UTC(),
|
||||
}
|
||||
}
|
||||
|
||||
func NewVoteWithTimestamp(elector string, choice Choice, timestamp time.Time) Vote {
|
||||
return Vote{
|
||||
Elector: elector,
|
||||
Choice: choice,
|
||||
timestamp: timestamp,
|
||||
}
|
||||
return Vote{
|
||||
Elector: elector,
|
||||
Choice: choice,
|
||||
timestamp: timestamp,
|
||||
}
|
||||
}
|
||||
|
||||
func (vote Vote) String() string {
|
||||
return fmt.Sprintf("%s %s %s", vote.timestamp.Format(time.DateTime), vote.Choice, vote.Elector)
|
||||
return fmt.Sprintf("%s %s %s", vote.timestamp.Format(time.DateTime), vote.Choice, vote.Elector)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue