apache / rocketmq-client-go

Compare 077cd3b ... +0 ... 47e9c8a


@@ -19,6 +19,7 @@
Loading
19 19
import (
20 20
	"context"
21 21
	"net"
22 +
	"strings"
22 23
23 24
	"go.uber.org/atomic"
24 25
)
@@ -31,7 +32,14 @@
Loading
31 32
32 33
func initConn(ctx context.Context, addr string) (*tcpConnWrapper, error) {
33 34
	var d net.Dialer
34 -
	conn, err := d.DialContext(ctx, "tcp", addr)
35 +
36 +
	dstAddr := addr
37 +
	if !isIPV4(dstAddr) {
38 +
		i := strings.LastIndex(addr, ":")
39 +
		dstAddr = "[" + addr[:i] + "]:" + addr[i+1:]
40 +
	}
41 +
42 +
	conn, err := d.DialContext(ctx, "tcp", dstAddr)
35 43
	if err != nil {
36 44
		return nil, err
37 45
	}
@@ -40,6 +48,19 @@
Loading
40 48
	}, nil
41 49
}
42 50
51 +
// reference by net.ParseIP
52 +
func isIPV4(s string) bool {
53 +
	for i := 0; i < len(s); i++ {
54 +
		switch s[i] {
55 +
		case '.':
56 +
			return true
57 +
		case ':':
58 +
			return false
59 +
		}
60 +
	}
61 +
	return false
62 +
}
63 +
43 64
func (wrapper *tcpConnWrapper) destroy() error {
44 65
	wrapper.closed.Swap(true)
45 66
	return wrapper.Conn.Close()

@@ -101,9 +101,6 @@
Loading
101 101
		return nil, errors.New("no name server addr found with resolver: " + resolver.Description())
102 102
	}
103 103
104 -
	if err := primitive.NamesrvAddr(addr).Check(); err != nil {
105 -
		return nil, err
106 -
	}
107 104
	nameSrvClient := remote.NewRemotingClient()
108 105
	return &namesrvs{
109 106
		srvs:             addr,

@@ -18,14 +18,9 @@
Loading
18 18
package primitive
19 19
20 20
import (
21 -
	"regexp"
22 21
	"strings"
23 22
)
24 23
25 -
var (
26 -
	ipRegex, _ = regexp.Compile(`^((25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))`)
27 -
)
28 -
29 24
type NamesrvAddr []string
30 25
31 26
func NewNamesrvAddr(s ...string) (NamesrvAddr, error) {
@@ -39,48 +34,11 @@
Loading
39 34
		ss = strings.Split(s[0], ";")
40 35
	}
41 36
42 -
	for _, srv := range ss {
43 -
		if err := verifyIP(srv); err != nil {
44 -
			return nil, err
45 -
		}
46 -
	}
47 -
48 37
	addrs := make(NamesrvAddr, 0)
49 38
	addrs = append(addrs, ss...)
50 39
	return addrs, nil
51 40
}
52 41
53 -
func (addr NamesrvAddr) Check() error {
54 -
	for _, srv := range addr {
55 -
		if err := verifyIP(srv); err != nil {
56 -
			return err
57 -
		}
58 -
	}
59 -
	return nil
60 -
}
61 -
62 -
var (
63 -
	httpPrefixRegex, _ = regexp.Compile("^(http|https)://")
64 -
)
65 -
66 -
func verifyIP(ip string) error {
67 -
	if httpPrefixRegex.MatchString(ip) {
68 -
		return nil
69 -
	}
70 -
	if strings.Contains(ip, ";") {
71 -
		return ErrMultiIP
72 -
	}
73 -
	ips := ipRegex.FindAllString(ip, -1)
74 -
	if len(ips) == 0 {
75 -
		return ErrIllegalIP
76 -
	}
77 -
78 -
	if len(ips) > 1 {
79 -
		return ErrMultiIP
80 -
	}
81 -
	return nil
82 -
}
83 -
84 42
var PanicHandler func(interface{})
85 43
86 44
func WithRecover(fn func()) {

@@ -124,6 +124,7 @@
Loading
124 124
	if ok {
125 125
		return conn.(*tcpConnWrapper), nil
126 126
	}
127 +
127 128
	tcpConn, err := initConn(ctx, addr)
128 129
	if err != nil {
129 130
		return nil, err

Learn more Showing 25 files with coverage changes found.

Changes in internal/route.go
-36
-2
+16
Loading file...
Changes in internal/utils/net.go
-4
-1
+1
Loading file...
Changes in primitive/base.go
-4
+2
Loading file...
Changes in internal/model.go
-24
-3
-9
Loading file...
Changes in producer/option.go
-5
-3
Loading file...
Changes in producer/selector.go
-1
+1
Loading file...
Changes in internal/trace.go
-8
-1
Loading file...
Changes in producer/producer.go
-11
-11
Loading file...
Changes in consumer/statistics.go
-4
+1
+1
Loading file...
Changes in internal/remote/remote_client.go
-1
+1
+1
Loading file...
Changes in consumer/push_consumer.go
-11
-1
-46
Loading file...
Changes in consumer/consumer.go
-1
-4
Loading file...
Changes in consumer/offset_store.go
-14
-7
Loading file...
Changes in internal/remote/tcp_conn.go
New
Loading file...
Changes in consumer/pull_consumer.go
-1
Loading file...
Changes in consumer/process_queue.go
-13
Loading file...
Changes in primitive/result.go
-2
Loading file...
internal/utils/compression.go
Loading file...
New file internal/utils/helper.go
New
Loading file...
Changes in internal/client.go
-62
Loading file...
Changes in internal/remote/codec.go
-10
-4
-5
Loading file...
Changes in internal/request.go
-66
Loading file...
Changes in primitive/nsresolver.go
-1
-1
Loading file...
Changes in primitive/message.go
-17
Loading file...
Changes in internal/namesrv.go
-1
-1
Loading file...
Files Coverage
consumer -0.15% 26.05%
internal -1.91% 21.31%
primitive -0.09% 28.11%
producer -1.49% 31.51%
Project Totals (49 files) 24.78%
Loading