Skip to content

Commit

Permalink
🦜 Upgrade to Go 1.21
Browse files Browse the repository at this point in the history
- Remove packages copied from std and change references.
- Move functions in [maps] that were dropped by std right before release to maphelper. golang/go#61538
- Use min, max.
  • Loading branch information
database64128 committed Aug 12, 2023
1 parent 5eccd51 commit 00a1171
Show file tree
Hide file tree
Showing 24 changed files with 75 additions and 1,941 deletions.
59 changes: 0 additions & 59 deletions cmp/cmp.go

This file was deleted.

96 changes: 0 additions & 96 deletions cmp/cmp_test.go

This file was deleted.

6 changes: 3 additions & 3 deletions cred/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package cred

import (
"bytes"
"cmp"
"context"
"encoding/json"
"errors"
"fmt"
"maps"
"os"
"slices"
"strings"
"sync"
"time"
"unsafe"

"github.com/database64128/shadowsocks-go/cmp"
"github.com/database64128/shadowsocks-go/maps"
"github.com/database64128/shadowsocks-go/mmap"
"github.com/database64128/shadowsocks-go/slices"
"github.com/database64128/shadowsocks-go/ss2022"
"go.uber.org/zap"
)
Expand Down
2 changes: 1 addition & 1 deletion dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"net"
"net/netip"
"os"
"slices"
"sync"
"time"

"github.com/database64128/shadowsocks-go/conn"
"github.com/database64128/shadowsocks-go/slices"
"github.com/database64128/shadowsocks-go/zerocopy"
"go.uber.org/zap"
"golang.org/x/net/dns/dnsmessage"
Expand Down
9 changes: 5 additions & 4 deletions domainset/matcher_domain.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package domainset

import (
"github.com/database64128/shadowsocks-go/maps"
"github.com/database64128/shadowsocks-go/slices"
"slices"

"github.com/database64128/shadowsocks-go/maphelper"
)

// MaxLinearDomains is the maximum number of domain rules under which a linear matcher can outperform a map matcher.
Expand Down Expand Up @@ -144,7 +145,7 @@ func (dmm DomainMapMatcher) Insert(rule string) {

// Rules implements the MatcherBuilder Rules method.
func (dmm DomainMapMatcher) Rules() []string {
return maps.Keys(dmm)
return maphelper.Keys(dmm)
}

// MatcherCount implements the MatcherBuilder MatcherCount method.
Expand All @@ -164,7 +165,7 @@ func (dmmp *DomainMapMatcher) AppendTo(matchers []Matcher) ([]Matcher, error) {
}

if len(dmm) <= MaxLinearDomains {
dlm := DomainLinearMatcher(maps.Keys(dmm))
dlm := DomainLinearMatcher(maphelper.Keys(dmm))
return dlm.AppendTo(matchers)
}

Expand Down
6 changes: 3 additions & 3 deletions domainset/matcher_suffix.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package domainset

import "github.com/database64128/shadowsocks-go/maps"
import "github.com/database64128/shadowsocks-go/maphelper"

// MaxLinearSuffixes is the maximum number of suffix rules under which a linear matcher can outperform a trie matcher.
const MaxLinearSuffixes = 4
Expand Down Expand Up @@ -102,7 +102,7 @@ func (smm SuffixMapMatcher) Insert(rule string) {

// Rules implements the MatcherBuilder Rules method.
func (smm SuffixMapMatcher) Rules() []string {
return maps.Keys(smm)
return maphelper.Keys(smm)
}

// MatcherCount implements the MatcherBuilder MatcherCount method.
Expand All @@ -122,7 +122,7 @@ func (smmp *SuffixMapMatcher) AppendTo(matchers []Matcher) ([]Matcher, error) {
}

if len(smm) <= MaxLinearSuffixes {
slm := SuffixLinearMatcher(maps.Keys(smm))
slm := SuffixLinearMatcher(maphelper.Keys(smm))
return slm.AppendTo(matchers)
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/database64128/shadowsocks-go

go 1.20
go 1.21.0

require (
github.com/database64128/tfo-go/v2 v2.0.6
github.com/database64128/tfo-go/v2 v2.1.0
github.com/gofiber/contrib/fiberzap/v2 v2.0.0
github.com/gofiber/fiber/v2 v2.48.0
github.com/oschwald/geoip2-golang v1.9.0
Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/database64128/tfo-go/v2 v2.0.6 h1:gA2SFhSl86g4Xg3aCxoq48VSrKoLhR07SZFFS8q3lfA=
github.com/database64128/tfo-go/v2 v2.0.6/go.mod h1:50S8TP6k6okfwUv1vKFqFoF9AiP2w45Ej5psJm53/oc=
github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/database64128/tfo-go/v2 v2.1.0 h1:t7cECxAPlqTnRJkBxaT4Pu/h6qvCrWpQuQfR10SHb0I=
github.com/database64128/tfo-go/v2 v2.1.0/go.mod h1:AnIPegFUu6WMEPWfWfSyP1Iu41l2AiX/oXBE8/sRG/c=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofiber/contrib/fiberzap/v2 v2.0.0 h1:pgFhveNyFlNzr8AQlRG7o1/EKMi+vOmX7RzBfPVgyyc=
github.com/gofiber/contrib/fiberzap/v2 v2.0.0/go.mod h1:NUXSG7SUq6b5NQfAyWCEdaaq3ZKsWz6atunN+NJ4gYY=
github.com/gofiber/fiber/v2 v2.48.0 h1:cRVMCb9aUJDsyHxGFLwz/sGzDggdailZZyptU9F9cU0=
Expand All @@ -26,17 +28,20 @@ github.com/oschwald/geoip2-golang v1.9.0/go.mod h1:BHK6TvDyATVQhKNbQBdrj9eAvuwOM
github.com/oschwald/maxminddb-golang v1.12.0 h1:9FnTOD0YOhP7DGxGsq4glzpGy5+w7pq50AS6wALUMYs=
github.com/oschwald/maxminddb-golang v1.12.0/go.mod h1:q0Nob5lTCqyQ8WT6FYgS1L7PXKVVbgiymefNwIjPzgY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.48.0 h1:oJWvHb9BIZToTQS3MuQ2R3bJZiNSa2KiNdeI8A+79Tc=
github.com/valyala/fasthttp v1.48.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.25.0 h1:4Hvk6GtkucQ790dqmj7l1eEnRdKm3k3ZUrUMS2d5+5c=
Expand All @@ -51,5 +56,6 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI=
lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k=
21 changes: 21 additions & 0 deletions maphelper/maphelper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package maphelper

// Keys returns the keys of the map m.
// The keys will be in an indeterminate order.
func Keys[M ~map[K]V, K comparable, V any](m M) []K {
r := make([]K, 0, len(m))
for k := range m {
r = append(r, k)
}
return r
}

// Values returns the values of the map m.
// The values will be in an indeterminate order.
func Values[M ~map[K]V, K comparable, V any](m M) []V {
r := make([]V, 0, len(m))
for _, v := range m {
r = append(r, v)
}
return r
}
42 changes: 0 additions & 42 deletions maps/maps.go

This file was deleted.

3 changes: 1 addition & 2 deletions portset/portset_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package portset

import (
"slices"
"strconv"
"testing"

"github.com/database64128/shadowsocks-go/slices"
)

func assertPanic(t *testing.T, f func()) {
Expand Down
2 changes: 1 addition & 1 deletion router/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"errors"
"fmt"
"net/netip"
"slices"

"github.com/database64128/shadowsocks-go/bitset"
"github.com/database64128/shadowsocks-go/conn"
"github.com/database64128/shadowsocks-go/dns"
"github.com/database64128/shadowsocks-go/domainset"
"github.com/database64128/shadowsocks-go/portset"
"github.com/database64128/shadowsocks-go/slices"
"github.com/database64128/shadowsocks-go/zerocopy"
"github.com/oschwald/geoip2-golang"
"go.uber.org/zap"
Expand Down
Loading

0 comments on commit 00a1171

Please sign in to comment.