🚨 go fmt; go mod tidy

This commit is contained in:
Brian Wiborg 2024-05-13 10:45:38 +02:00
parent fb2a29be51
commit b0657a3fb2
No known key found for this signature in database
GPG key ID: BE53FA9286B719D6
20 changed files with 715 additions and 722 deletions

View file

@ -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)
}

View file

@ -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)
}