3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-22 03:49:27 +01:00

Merge pull request #2084 from slingamn/go_upgrade_121

bump go to v1.21
This commit is contained in:
Shivaram Lingamneni 2023-08-16 08:46:34 -07:00 committed by GitHub
commit 3b3e8c0004
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 23 additions and 43 deletions

View File

@ -19,7 +19,7 @@ jobs:
- name: "setup go"
uses: "actions/setup-go@v3"
with:
go-version: "1.20"
go-version: "1.21"
- name: "install python3-pytest"
run: "sudo apt install -y python3-pytest"
- name: "make install"

View File

@ -1,5 +1,5 @@
## build ergo binary
FROM golang:1.20-alpine AS build-env
FROM golang:1.21-alpine AS build-env
RUN apk upgrade -U --force-refresh --no-cache && apk add --no-cache --purge --clean-protected -l -u make git

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/ergochat/ergo
go 1.20
go 1.21
require (
code.cloudfoundry.org/bytefmt v0.0.0-20200131002437-cf55d5288a48

View File

@ -7,6 +7,7 @@ package irc
import (
"fmt"
"maps"
"strconv"
"strings"
"time"
@ -158,7 +159,7 @@ func (channel *Channel) ExportRegistration() (info RegisteredChannel) {
info.Bans = channel.lists[modes.BanMask].Masks()
info.Invites = channel.lists[modes.InviteMask].Masks()
info.Excepts = channel.lists[modes.ExceptMask].Masks()
info.AccountToUMode = utils.CopyMap(channel.accountToUMode)
info.AccountToUMode = maps.Clone(channel.accountToUMode)
info.Settings = channel.settings

View File

@ -6,6 +6,7 @@ package irc
import (
"fmt"
"regexp"
"slices"
"sort"
"strings"
"time"
@ -218,7 +219,7 @@ func csAmodeHandler(service *ircService, server *Server, client *Client, command
// check for anything valid as a channel mode change that is not valid
// as an AMODE change
for _, modeChange := range modeChanges {
if !utils.SliceContains(modes.ChannelUserModes, modeChange.Mode) {
if !slices.Contains(modes.ChannelUserModes, modeChange.Mode) {
invalid = true
}
}

View File

@ -8,6 +8,7 @@ package irc
import (
"crypto/x509"
"fmt"
"maps"
"net"
"runtime/debug"
"strconv"
@ -1743,7 +1744,7 @@ func (client *Client) handleRegisterTimeout() {
func (client *Client) copyLastSeen() (result map[string]time.Time) {
client.stateMutex.RLock()
defer client.stateMutex.RUnlock()
return utils.CopyMap(client.lastSeen)
return maps.Clone(client.lastSeen)
}
// these are bit flags indicating what part of the client status is "dirty"

View File

@ -4,9 +4,8 @@
package irc
import (
"maps"
"time"
"github.com/ergochat/ergo/irc/utils"
)
// fakelag is a system for artificially delaying commands when a user issues
@ -40,7 +39,7 @@ func (fl *Fakelag) Initialize(config FakelagConfig) {
fl.config = config
// XXX don't share mutable member CommandBudgets:
if config.CommandBudgets != nil {
fl.config.CommandBudgets = utils.CopyMap(config.CommandBudgets)
fl.config.CommandBudgets = maps.Clone(config.CommandBudgets)
}
fl.nowFunc = time.Now
fl.sleepFunc = time.Sleep

View File

@ -5,6 +5,7 @@ package irc
import (
"fmt"
"maps"
"net"
"time"
@ -515,7 +516,7 @@ func (client *Client) GetReadMarker(cfname string) (result string) {
func (client *Client) copyReadMarkers() (result map[string]time.Time) {
client.stateMutex.RLock()
defer client.stateMutex.RUnlock()
return utils.CopyMap(client.readMarkers)
return maps.Clone(client.readMarkers)
}
func (client *Client) SetReadMarker(cfname string, now time.Time) (result time.Time) {

View File

@ -4,6 +4,7 @@
package history
import (
"slices"
"sync"
"time"
@ -155,7 +156,7 @@ func (list *Buffer) betweenHelper(start, end Selector, cutoff time.Time, pred Pr
defer func() {
if !ascending {
utils.ReverseSlice(results)
slices.Reverse(results)
}
}()
@ -262,7 +263,7 @@ func (list *Buffer) listCorrespondents(start, end Selector, cutoff time.Time, li
}
if !ascending {
utils.ReverseSlice(results)
slices.Reverse(results)
}
return

View File

@ -4,10 +4,9 @@
package history
import (
"slices"
"sort"
"time"
"github.com/ergochat/ergo/irc/utils"
)
type TargetListing struct {
@ -35,8 +34,8 @@ func MergeTargets(base []TargetListing, extra []TargetListing, start, end time.T
results = make([]TargetListing, 0, prealloc)
if !ascending {
utils.ReverseSlice(base)
utils.ReverseSlice(extra)
slices.Reverse(base)
slices.Reverse(extra)
}
for len(results) < limit {
@ -66,7 +65,7 @@ func MergeTargets(base []TargetListing, extra []TargetListing, start, end time.T
}
if !ascending {
utils.ReverseSlice(results)
slices.Reverse(results)
}
return
}

View File

@ -11,6 +11,7 @@ import (
"fmt"
"io"
"runtime/debug"
"slices"
"strings"
"sync"
"sync/atomic"
@ -917,7 +918,7 @@ func (mysql *MySQL) betweenTimestamps(ctx context.Context, target, correspondent
results, err = mysql.selectItems(ctx, queryBuf.String(), args...)
if err == nil && !ascending {
utils.ReverseSlice(results)
slices.Reverse(results)
}
return
}
@ -965,7 +966,7 @@ func (mysql *MySQL) listCorrespondentsInternal(ctx context.Context, target strin
}
if !ascending {
utils.ReverseSlice(results)
slices.Reverse(results)
}
return

View File

@ -27,27 +27,3 @@ func SetLiteral[T comparable](elems ...T) HashSet[T] {
}
return result
}
func CopyMap[K comparable, V any](input map[K]V) (result map[K]V) {
result = make(map[K]V, len(input))
for key, value := range input {
result[key] = value
}
return
}
// reverse the order of a slice in place
func ReverseSlice[T any](results []T) {
for i, j := 0, len(results)-1; i < j; i, j = i+1, j-1 {
results[i], results[j] = results[j], results[i]
}
}
func SliceContains[T comparable](slice []T, elem T) (result bool) {
for _, t := range slice {
if elem == t {
return true
}
}
return false
}