From 0324e9871a9b52ea5464eb3fd22fa2eae054ad57 Mon Sep 17 00:00:00 2001 From: David Florness Date: Mon, 18 Jan 2021 22:50:48 -0500 Subject: [PATCH] find . -name '*.go' | xargs gofmt -w ...with a few modifications from me --- election/election.go | 20 ++++++++++---------- election/map.go | 6 +++--- election/voter.go | 12 ++++++------ matrix/data.go | 12 ++++++------ ui/tui.go | 4 ++-- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/election/election.go b/election/election.go index 00af9cc..6a8ee23 100644 --- a/election/election.go +++ b/election/election.go @@ -10,16 +10,16 @@ import ( type Election struct { sync.RWMutex - Candidates []Candidate `json:"candidates"` - CreateEventId id.EventID `json:"create_event_id"` - CreationTimestamp int64 `json:"creation_timestamp"` - Creator id.UserID `json:"creator"` - FinalVoters *[]id.EventID `json:"final_voters,omitempty"` - Joins map[id.EventID]*Voter `json:"joins"` - LocalVoter *LocalVoter `json:"local_voter,omitempty"` - RoomID id.RoomID `json:"room_id"` - StartEvt *event.Event `json:"start_evt,omitempty"` - Title string `json:"title"` + Candidates []Candidate `json:"candidates"` + CreateEventId id.EventID `json:"create_event_id"` + CreationTimestamp int64 `json:"creation_timestamp"` + Creator id.UserID `json:"creator"` + FinalVoters *[]id.EventID `json:"final_voters,omitempty"` + Joins map[id.EventID]*Voter `json:"joins"` + LocalVoter *LocalVoter `json:"local_voter,omitempty"` + RoomID id.RoomID `json:"room_id"` + StartEvt *event.Event `json:"start_evt,omitempty"` + Title string `json:"title"` } func NewElection(candidates []Candidate, createEventId id.EventID, diff --git a/election/map.go b/election/map.go index 9ca94c9..52b56ac 100644 --- a/election/map.go +++ b/election/map.go @@ -8,7 +8,7 @@ import ( "maunium.net/go/mautrix/id" ) -type ElectionsMap struct{ +type ElectionsMap struct { sync.RWMutex M map[id.EventID]*Election L []*Election // sorted list of elections by CreationTimestamp (newest to oldest) @@ -57,7 +57,7 @@ func (em *ElectionsMap) GetOk(createEventID id.EventID) (*Election, bool) { return el, ok } -func (em *ElectionsMap) GetI(i int) (*Election) { +func (em *ElectionsMap) GetI(i int) *Election { em.RLock() defer em.RUnlock() return em.L[i] @@ -88,7 +88,7 @@ func (em *ElectionsMap) insort(createEventID id.EventID, el *Election) { i := sort.Search(len(em.L), func(i int) bool { return em.L[i].CreationTimestamp < el.CreationTimestamp }) - newList := make([]*Election, len(em.L) + 1) + newList := make([]*Election, len(em.L)+1) copy(newList[:i], em.L[:i]) newList[i] = el copy(newList[i+1:], em.L[i:]) diff --git a/election/voter.go b/election/voter.go index d2a38cc..b838f1b 100644 --- a/election/voter.go +++ b/election/voter.go @@ -247,12 +247,12 @@ func (el *Election) GetSums(client *mautrix.Client) { M := constructPolyMatrix(el) M.RREF() constant := M[0][len(M[0])-1] - if !constant.IsInt() { - panic("constant term is not an integer") - } + if !constant.IsInt() { + panic("constant term is not an integer") + } result := constant.Num().Bytes() // number of bytes we need to insert at the front since they're zero - diff := (len(el.Candidates)*len(el.Candidates)) - len(result) + diff := (len(el.Candidates) * len(el.Candidates)) - len(result) result = append(make([]byte, diff), result...) printResults(result, el.Candidates) } @@ -263,7 +263,7 @@ func constructPolyMatrix(el *Election) math.Matrix { i := 0 for _, voterJoinId := range *el.FinalVoters { voter := el.Joins[voterJoinId] - mat[i] = make([]big.Rat, len(mat) + 1) // includes column for sum + mat[i] = make([]big.Rat, len(mat)+1) // includes column for sum row := mat[i] row[0].SetInt64(1) var j int64 @@ -284,7 +284,7 @@ func printResults(result []byte, candidates []Candidate) { for i, cand := range candidates { for j, vs := range candidates { if i != j { - fmt.Printf("%s over %s: %d\n", cand, vs, result[i * n + j]) + fmt.Printf("%s over %s: %d\n", cand, vs, result[i*n+j]) } } } diff --git a/matrix/data.go b/matrix/data.go index 15d6585..d6e9abf 100644 --- a/matrix/data.go +++ b/matrix/data.go @@ -13,11 +13,11 @@ import ( ) type Data struct { - AccessToken string `json:"access_token"` - DeviceID id.DeviceID `json:"device_id"` - Homeserver string `json:"homeserver"` - UserID id.UserID `json:"user_id"` - Username string `json:"username"` + AccessToken string `json:"access_token"` + DeviceID id.DeviceID `json:"device_id"` + Homeserver string `json:"homeserver"` + UserID id.UserID `json:"user_id"` + Username string `json:"username"` } var dataFname = xdg.DataHome() + "/tallyard/data.json" @@ -58,7 +58,7 @@ func stripNewline(s string) string { func InquireForData() (data *Data, err error) { var ( password string - reader = bufio.NewReader(os.Stdin) + reader = bufio.NewReader(os.Stdin) ) data = &Data{} diff --git a/ui/tui.go b/ui/tui.go index 4c8de01..ce0f176 100644 --- a/ui/tui.go +++ b/ui/tui.go @@ -94,7 +94,7 @@ func RoomTUI(client *mautrix.Client, roomID id.RoomID, elections *election.Elect f(title, fmt.Sprintf("created by %s, ID: %s", el.Creator, el.CreateEventId), rune('a'+i), nil) i++ } - } + } go func() { for alive { app.QueueUpdateDraw(update) @@ -108,7 +108,7 @@ func RoomTUI(client *mautrix.Client, roomID id.RoomID, elections *election.Elect if i > 0 { // user wants to join election - el = elections.GetI(i-1) + el = elections.GetI(i - 1) // don't need to lock because this goroutine controls LocalVoter if el.LocalVoter != nil { if el.LocalVoter.Ballot != nil { -- 2.38.4