mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-10-29 15:02:30 +00:00
Apply go fix to simplify using modern features
This patch contains the result of running `go fix ./...`, which applies simplifications that make use of modern language features. There are no logic or behaviour changes.
This commit is contained in:
@@ -168,14 +168,14 @@ func printDiff(print func(s string), expected, got string) {
|
||||
|
||||
// expected lines and map.
|
||||
eM := map[string]int{}
|
||||
for _, l := range strings.Split(expected, "\n") {
|
||||
for l := range strings.SplitSeq(expected, "\n") {
|
||||
eM[l]++
|
||||
lines = append(lines, l)
|
||||
}
|
||||
|
||||
// got lines and map.
|
||||
gM := map[string]int{}
|
||||
for _, l := range strings.Split(got, "\n") {
|
||||
for l := range strings.SplitSeq(got, "\n") {
|
||||
gM[l]++
|
||||
lines = append(lines, l)
|
||||
}
|
||||
|
||||
+16
-17
@@ -15,6 +15,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -249,26 +250,27 @@ func (q *Queue) Remove(id string) {
|
||||
func (q *Queue) DumpString() string {
|
||||
q.mu.RLock()
|
||||
defer q.mu.RUnlock()
|
||||
s := "# Queue status\n\n"
|
||||
s += fmt.Sprintf("date: %v\n", time.Now())
|
||||
s += fmt.Sprintf("length: %d\n\n", len(q.q))
|
||||
var s strings.Builder
|
||||
s.WriteString("# Queue status\n\n")
|
||||
s.WriteString(fmt.Sprintf("date: %v\n", time.Now()))
|
||||
s.WriteString(fmt.Sprintf("length: %d\n\n", len(q.q)))
|
||||
|
||||
for id, item := range q.q {
|
||||
s += fmt.Sprintf("## Item %s\n", id)
|
||||
s.WriteString(fmt.Sprintf("## Item %s\n", id))
|
||||
item.Lock()
|
||||
s += fmt.Sprintf("created at: %s\n", item.CreatedAt)
|
||||
s += fmt.Sprintf("from: %s\n", item.From)
|
||||
s += fmt.Sprintf("to: %s\n", item.To)
|
||||
s.WriteString(fmt.Sprintf("created at: %s\n", item.CreatedAt))
|
||||
s.WriteString(fmt.Sprintf("from: %s\n", item.From))
|
||||
s.WriteString(fmt.Sprintf("to: %s\n", item.To))
|
||||
for _, rcpt := range item.Rcpt {
|
||||
s += fmt.Sprintf("%s %s (%s)\n", rcpt.Status, rcpt.Address, rcpt.Type)
|
||||
s += fmt.Sprintf(" original address: %s\n", rcpt.OriginalAddress)
|
||||
s += fmt.Sprintf(" last failure: %q\n", rcpt.LastFailureMessage)
|
||||
s.WriteString(fmt.Sprintf("%s %s (%s)\n", rcpt.Status, rcpt.Address, rcpt.Type))
|
||||
s.WriteString(fmt.Sprintf(" original address: %s\n", rcpt.OriginalAddress))
|
||||
s.WriteString(fmt.Sprintf(" last failure: %q\n", rcpt.LastFailureMessage))
|
||||
}
|
||||
item.Unlock()
|
||||
s += "\n"
|
||||
s.WriteString("\n")
|
||||
}
|
||||
|
||||
return s
|
||||
return s.String()
|
||||
}
|
||||
|
||||
// An Item in the queue.
|
||||
@@ -458,11 +460,8 @@ func rewriteSender(from, originalAddr string) string {
|
||||
func (item *Item) countRcpt(statuses ...Recipient_Status) int {
|
||||
c := 0
|
||||
for _, rcpt := range item.Rcpt {
|
||||
for _, status := range statuses {
|
||||
if rcpt.Status == status {
|
||||
c++
|
||||
break
|
||||
}
|
||||
if slices.Contains(statuses, rcpt.Status) {
|
||||
c++
|
||||
}
|
||||
}
|
||||
return c
|
||||
|
||||
@@ -277,7 +277,7 @@ func TestNextDelay(t *testing.T) {
|
||||
}
|
||||
for _, c := range cases {
|
||||
// Repeat each case a few times to exercise the perturbation a bit.
|
||||
for i := 0; i < 10; i++ {
|
||||
for range 10 {
|
||||
delay := nextDelay(time.Now().Add(-c.since))
|
||||
|
||||
max := c.min + 1*time.Minute
|
||||
|
||||
Reference in New Issue
Block a user