fix: golang1.19 can't compile

This commit is contained in:
wwqgtxx 2023-02-26 22:20:25 +08:00
parent d36f9c2ac8
commit c8c078e78a
4 changed files with 24 additions and 8 deletions

View file

@ -2,7 +2,6 @@ package dialer
import (
"context"
"errors"
"fmt"
"net"
"net/netip"
@ -19,7 +18,6 @@ var (
actualSingleStackDialContext = serialSingleStackDialContext
actualDualStackDialContext = serialDualStackDialContext
tcpConcurrent = false
ErrorInvalidedNetworkStack = errors.New("invalided network stack")
fallbackTimeout = 300 * time.Millisecond
)
@ -227,7 +225,7 @@ func dualStackDialContext(
func parallelDialContext(ctx context.Context, network string, ips []netip.Addr, port string, opt *option) (net.Conn, error) {
if len(ips) == 0 {
return nil, errors.New("no ip address")
return nil, ErrorNoIpAddress
}
results := make(chan dialResult)
returned := make(chan struct{})
@ -272,7 +270,7 @@ func parallelDialContext(ctx context.Context, network string, ips []netip.Addr,
func serialDialContext(ctx context.Context, network string, ips []netip.Addr, port string, opt *option) (net.Conn, error) {
if len(ips) == 0 {
return nil, errors.New("no ip address")
return nil, ErrorNoIpAddress
}
var (
conn net.Conn
@ -286,7 +284,7 @@ func serialDialContext(ctx context.Context, network string, ips []netip.Addr, po
errs = append(errs, err)
}
}
return nil, errors.Join(errs...)
return nil, errorsJoin(errs...)
}
type dialResult struct {

18
component/dialer/error.go Normal file
View file

@ -0,0 +1,18 @@
package dialer
import (
"errors"
E "github.com/sagernet/sing/common/exceptions"
)
var (
ErrorNoIpAddress = errors.New("no ip address")
ErrorInvalidedNetworkStack = errors.New("invalided network stack")
)
func errorsJoin(errs ...error) error {
// compatibility with golang<1.20
// maybe use errors.Join(errs...) is better after we drop the old version's support
return E.Errors(errs...)
}

2
go.mod
View file

@ -26,7 +26,7 @@ require (
github.com/mroth/weightedrand/v2 v2.0.0
github.com/oschwald/geoip2-golang v1.8.0
github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97
github.com/sagernet/sing v0.1.8-0.20230226075703-7def9588a57c
github.com/sagernet/sing v0.1.8-0.20230226133421-e83948367009
github.com/sagernet/sing-shadowtls v0.0.0-20230221130515-dac782ca098e
github.com/sagernet/sing-vmess v0.1.2
github.com/sagernet/tfo-go v0.0.0-20230207095944-549363a7327d

4
go.sum
View file

@ -127,8 +127,8 @@ github.com/sagernet/go-tun2socks v1.16.12-0.20220818015926-16cb67876a61/go.mod h
github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97 h1:iL5gZI3uFp0X6EslacyapiRz7LLSJyr4RajF/BhMVyE=
github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97/go.mod h1:xLnfdiJbSp8rNqYEdIW/6eDO4mVoogml14Bh2hSiFpM=
github.com/sagernet/sing v0.0.0-20220817130738-ce854cda8522/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
github.com/sagernet/sing v0.1.8-0.20230226075703-7def9588a57c h1:PDkrM1NhN03w6AtmBxQldH/mmqNGbKhIi6uWdiTOf9g=
github.com/sagernet/sing v0.1.8-0.20230226075703-7def9588a57c/go.mod h1:jt1w2u7lJQFFSGLiRrRIs5YWmx4kAPfWuOejuDW9qMk=
github.com/sagernet/sing v0.1.8-0.20230226133421-e83948367009 h1:KjrXGv09UlBl3Rj57XInk6u2TAxqpPfOJ2kUgV5B2lw=
github.com/sagernet/sing v0.1.8-0.20230226133421-e83948367009/go.mod h1:jt1w2u7lJQFFSGLiRrRIs5YWmx4kAPfWuOejuDW9qMk=
github.com/sagernet/sing-shadowtls v0.0.0-20230221130515-dac782ca098e h1:S1fd0kB9aEU68dd269AQy783sUlFu/2fSh/4YYVJ/Oc=
github.com/sagernet/sing-shadowtls v0.0.0-20230221130515-dac782ca098e/go.mod h1:Kn1VUIprdkwCgkS6SXYaLmIpKzQbqBIKJBMY+RvBhYc=
github.com/sagernet/sing-vmess v0.1.2 h1:RbOZNAId2LrCai8epMoQXlf0XTrou0bfcw08hNBg6lM=