Skip to content

Commit 66d53fb

Browse files
Parse inet as net.IP
1 parent 480b8b7 commit 66d53fb

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

helpers.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"encoding/hex"
2929
"fmt"
3030
"math/big"
31+
"net"
3132
"reflect"
3233
"strconv"
3334
"strings"
@@ -43,7 +44,9 @@ type RowData struct {
4344

4445
func goType(t TypeInfo) (reflect.Type, error) {
4546
switch t.Type() {
46-
case TypeVarchar, TypeAscii, TypeInet, TypeText:
47+
case TypeInet:
48+
return reflect.TypeOf(*new(net.IP)), nil
49+
case TypeVarchar, TypeAscii, TypeText:
4750
return reflect.TypeOf(*new(string)), nil
4851
case TypeBigInt, TypeCounter:
4952
return reflect.TypeOf(*new(int64)), nil

host_source.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,10 @@ func hostInfoFromMap(row map[string]interface{}, host *HostInfo, translateAddres
556556
}
557557
host.version.Set(version)
558558
case "peer":
559-
ip, ok := value.(string)
559+
host.peer, ok = value.(net.IP)
560560
if !ok {
561561
return nil, fmt.Errorf(assertErrorMsg, "peer")
562562
}
563-
host.peer = net.ParseIP(ip)
564563
case "cluster_name":
565564
host.clusterName, ok = value.(string)
566565
if !ok {
@@ -572,35 +571,30 @@ func hostInfoFromMap(row map[string]interface{}, host *HostInfo, translateAddres
572571
return nil, fmt.Errorf(assertErrorMsg, "partitioner")
573572
}
574573
case "broadcast_address":
575-
ip, ok := value.(string)
574+
host.broadcastAddress, ok = value.(net.IP)
576575
if !ok {
577576
return nil, fmt.Errorf(assertErrorMsg, "broadcast_address")
578577
}
579-
host.broadcastAddress = net.ParseIP(ip)
580578
case "preferred_ip":
581-
ip, ok := value.(string)
579+
host.preferredIP, ok = value.(net.IP)
582580
if !ok {
583581
return nil, fmt.Errorf(assertErrorMsg, "preferred_ip")
584582
}
585-
host.preferredIP = net.ParseIP(ip)
586583
case "rpc_address":
587-
ip, ok := value.(string)
584+
host.rpcAddress, ok = value.(net.IP)
588585
if !ok {
589586
return nil, fmt.Errorf(assertErrorMsg, "rpc_address")
590587
}
591-
host.rpcAddress = net.ParseIP(ip)
592588
case "native_address":
593-
ip, ok := value.(string)
589+
host.rpcAddress, ok = value.(net.IP)
594590
if !ok {
595591
return nil, fmt.Errorf(assertErrorMsg, "native_address")
596592
}
597-
host.rpcAddress = net.ParseIP(ip)
598593
case "listen_address":
599-
ip, ok := value.(string)
594+
host.listenAddress, ok = value.(net.IP)
600595
if !ok {
601596
return nil, fmt.Errorf(assertErrorMsg, "listen_address")
602597
}
603-
host.listenAddress = net.ParseIP(ip)
604598
case "native_port":
605599
native_port, ok := value.(int)
606600
if !ok {

0 commit comments

Comments
 (0)